Is there any way of setting a color to an icon drawable? So that the icon's color would be overwritten by my custom color ?
<item android:drawable="@drawable/icon1"
//set color to my icon here
android:state_pressed="true" />
<item android:drawable="@drawable/icon2"
//set color to my icon here
/>
Try the following:
android:drawableTint="@color/icon_color"
Use the tint attribute on your image element (or whatever you use to show an image), for example:
<ImageView android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/ic_drawable_resource_name"
android:tint="@color/color_name"/>
You can use this snippet
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false">
<bitmap android:src="@drawable/signup_checkbox_empty" android:tint="@color/turquoise" />
</item>
<item android:state_checked="true">
<bitmap android:src="@drawable/signup_checkbox_full" android:tint="@color/turquoise" />
</item>
<item>
<bitmap android:src="@drawable/signup_checkbox_empty" android:tint="@color/turquoise" />
</item>
</selector>
In android L (5.0) there is a TINT feature which allows to change the color of a drawable icon. You can check an example here.
For earlier APIs you have to use multiple drawables with selector strategy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With