I trying to change the colours in this drawable dynamically.
The drawable xml is:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/status_colour_outer"
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp">
<shape
android:shape="oval">
<solid android:color="@color/red"/>
</shape>
</item>
<item android:id="@+id/status_colour_inner">
<shape
android:shape="oval">
<stroke
android:width="2dp"
android:color="@color/red"/>
</shape>
</item>
</layer-list>
i need to change both the layers to the same colour dynamically from a webservice response.
The following code works only but only changes the
@+id/status_colour_inner
colour but doesn't change the outer yet it is referencing the layer:
LayerDrawable layers = (LayerDrawable) ContextCompat.getDrawable(getContext(), R.drawable.status_colour);
GradientDrawable shape = (GradientDrawable) layers.findDrawableByLayerId(R.id.status_colour_inner);
GradientDrawable shape1 = (GradientDrawable) layers.findDrawableByLayerId(R.id.status_colour_outer);
shape.setColor(Color.parseColor(mColours.getDisplayClasses().get(position).getColour()));
shape1.setColor(Color.parseColor(mColours.getDisplayClasses().get(position).getColour()));
aView.setBackground(layers);
mColours.getDisplayClasses().get(position).getColour()
all this does is return a String of the colour like "#B5FFC9"