When I use drawables from the AppCompat
library for my Toolbar
menu items the tinting works as expected. Like this:
<item
android:id="@+id/action_clear"
android:icon="@drawable/abc_ic_clear_mtrl_alpha" <-- from AppCompat
android:title="@string/clear" />
But if I use my own drawables or actually even copy the drawables from the AppCompat
library to my own project it will not tint at all.
<item
android:id="@+id/action_clear"
android:icon="@drawable/abc_ic_clear_mtrl_alpha_copy" <-- copy from AppCompat
android:title="@string/clear" />
Is there some special magic in the AppCompat
Toolbar
that only tint drawables from that library? Any way to get this to work with my own drawables?
Running this on API Level 19 device with compileSdkVersion = 21
and targetSdkVersion = 21
, and also using everything from AppCompat
abc_ic_clear_mtrl_alpha_copy
is an exact copy of the abc_ic_clear_mtrl_alpha
png from AppCompat
Edit:
The tinting is based on the value I have set for android:textColorPrimary
in my theme.
E.g. <item name="android:textColorPrimary">#00FF00</item>
would give me a green tint color.
Screenshots
Tinting working as expected with drawable from AppCompat
Tinting not working with drawable copied from AppCompat
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…