我有一个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根据某些条件在运行时更改形状纯色.这该怎么做?
如何以编程方式更改#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