Created
September 13, 2018 22:27
-
-
Save JakeSteam/1113e35ab13d4998f94d2d4a14c720f8 to your computer and use it in GitHub Desktop.
"Recolouring / modifying multi-layer drawables dynamically in Android" for blog.jakelee.co.uk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Changing colour | |
val layerDrawable = (ImageView)findViewById(R.id.my_drawable).drawable as LayerDrawable | |
val backgroundDrawable = layerDrawable.findDrawableByLayerId(R.id.background_circle) as GradientDrawable | |
backgroundDrawable.setColor(ContextCompat.getColor(context, R.color.my_colour)) | |
// Changing drawable | |
layerDrawable.setDrawableByLayerId(R.id.foreground_icon, ContextCompat.getDrawable(context, R.drawable.new_foreground_icon)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item | |
android:id="@+id/background_circle"> | |
<shape android:shape="oval"> | |
<solid android:color="@color/orange" /> | |
</shape> | |
</item> | |
<item android:id="@+id/foreground_icon"> | |
<shape> | |
<solid android:color="@android:color/transparent" /> | |
</shape> | |
</item> | |
</layer-list> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment