Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
"Recolouring / modifying multi-layer drawables dynamically in Android" for
// Changing colour
val layerDrawable = (ImageView)findViewById( as LayerDrawable
val backgroundDrawable = layerDrawable.findDrawableByLayerId( as GradientDrawable
backgroundDrawable.setColor(ContextCompat.getColor(context, R.color.my_colour))
// Changing drawable
layerDrawable.setDrawableByLayerId(, ContextCompat.getDrawable(context, R.drawable.new_foreground_icon))
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="">
<shape android:shape="oval">
<solid android:color="@color/orange" />
<item android:id="@+id/foreground_icon">
<solid android:color="@android:color/transparent" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.