Are you trying to randomly change the color of a specific layer inside a LayerDrawable?
If so, you can find the target drawable within the LayerDrawable either by index (getDrawable(int index)
) or by ID (findDrawableByLayerId(int id)
), and then change its color using setTint(int tintColor)
.
If your LayerDrawable is created in XML, you can directly assign an ID to each layer like this:
<item
android:id="@+id/background_layer"
android:drawable="@drawable/bottom_background_drawable" />