相关疑难解决方法(0)

在用作背景的Drawable xml中在运行时更改形状纯色

我有一个Drawable xml文件(background.xml):

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape>
         ...........
        </shape>
    </item>

    <item android:id="@+id/shape_id">
        <shape android:shape="rectangle">
            <solid android:color="#ffefefef" /> 
        </shape>
    </item>

</layer-list>
Run Code Online (Sandbox Code Playgroud)

由LinearLayout使用:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/background"
    android:id="@+id/layout_id"
    >
Run Code Online (Sandbox Code Playgroud)

现在我需要shape_id根据某些条件在运行时更改形状纯色.这该怎么做?

layout android shape drawable

29
推荐指数
1
解决办法
2万
查看次数

以编程方式更改图层列表中的形状颜色

如何以编程方式更改#000000图层列表中形状的颜色()?

这是我的图层列表:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#000000" /> // CHANGE THIS COLOR
        </shape>
    </item>
    <item android:left="5dp">
        <shape android:shape="rectangle">
            <solid android:color="@color/bg" />
        </shape>
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml android-fragments android-activity

29
推荐指数
3
解决办法
2万
查看次数