I am trying to add support for the new Material UI in my apps, but I have encountered an annoying situation.
Before SDK 14 the black app menu needed white icons. Starting with SDK 14 the Holo light theme needed dark icons. Now when migrating to Material I need white icons once again. So basically I have a folder drawable-hdpi-v11, one drawable-hdpi-v14 and one drawable-hdpi-v21. drawable-hdpi-v11 and drawable-hdpi-v21 have the same images and of course Lint warns me that I have the same resources duplicated.
I have look into aliases Creating alias resources, but it doesn't seem to offer the functionality I need. Do you know any way to obtain the same result (white images for SDK<14 or SDK>=21, dark for SDK>=14 and SDK<21) without duplicating the resources?
You want @drawable/ic_action_heart
to resolve to:
In that case:
Have a dark version of the icon as ic_action_heart.png
in res/drawable-hdpi-v14/
Have a light version of the icon as ic_action_heart_white.png
in res/drawable-hdpi/
Have a drawable alias, named ic_action_heart.xml
, in res/drawable-hdpi-v21/
, pointing to @drawable/ic_action_heart_white
Have a drawable alias, named ic_action_heart.xml
, in res/drawable-hdpi/
, pointing to @drawable/ic_action_heart_white
And, of course, you would have the same basic structure in other density buckets (e.g., -xxhdpi
). Since density is more important than is API level, I think you will need to have density-specific versions of the aliases.
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