Android:动态更改XML中的形状颜色

Android:动态更改XML中的形状颜色,android,android-layout,android-xml,Android,Android Layout,Android Xml,我将此自定义xml应用为TextView背景 它像我期望的那样工作。然而,这个xml中有两个形状,我想动态地更改这两个形状的颜色 经过搜索,我没有找到任何解决这个问题的方法 有什么想法吗?请指教,谢谢 <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <rotate android:fromDegree

我将此自定义xml应用为TextView背景

它像我期望的那样工作。然而,这个xml中有两个形状,我想动态地更改这两个形状的颜色

经过搜索,我没有找到任何解决这个问题的方法

有什么想法吗?请指教,谢谢

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <rotate
                android:fromDegrees="0"
                android:toDegrees="0"
                android:pivotX="0%"
                android:pivotY="0%" >
            <shape
                    android:shape="rectangle" >
                <solid android:color="#ff0000" />
            </shape>
        </rotate>
    </item>
    <item>
        <rotate
                android:fromDegrees="-405"
                android:toDegrees="0"
                android:pivotX="0%"
                android:pivotY="100%" >
            <shape
                    android:shape="rectangle" >
                <solid android:color="#000000" />
            </shape>
        </rotate>
    </item>

</layer-list>

如果只想更改一次颜色,则可以使用另一个具有相同形状但具有新颜色值的自定义xml,并将textview的背景动态设置为该xml。

尝试:或