In Andoroid, I need to change a change a specific shape's color in a drawable xml with many shapes with colors dynamically. This drawable applied as a background to a Linearlayout
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/bandItem">
<shape android:shape="rectangle">
<solid
android:id="@+id/bandColor" // Change This -->
android:color="@color/band_traits" />
</shape>
</item>
<item
android:id="@+id/backgroundItem"
android:left="10dp">
<shape android:shape="rectangle">
<solid
android:id="@+id/backColor"
android:color="@color/colorWhite" />
</shape>
</item>
</layer-list>
In the above drawable XML , I need to change the @color/colorGreen
(marked above ) to needed color based on the condition.
I tried some stack overflow answers, but they are changing entire drawable. I need only to change the one marked as // Change this --->
Please help me !
(OR is it possible to design the above XML completely in Kotlin and apply as background object to a Linearlayout ?)