Reputation: 1092
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
/>
Upvotes: 12
Views: 31823
Reputation: 119
Use app:drawableTint="@color/yourColor"
in the xml instade android:drawableTint="@color/yourColor"
. It has the backward compatibility.
Upvotes: 1
Reputation: 114
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"/>
Upvotes: 5
Reputation: 434
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>
Upvotes: 11