Issue
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?
Solution
You want @drawable/ic_action_heart
to resolve to:
- white on < 14
- dark on >= 14 and < 21
- white on >= 21
In that case:
Have a dark version of the icon as
ic_action_heart.png
inres/drawable-hdpi-v14/
Have a light version of the icon as
ic_action_heart_white.png
inres/drawable-hdpi/
Have a drawable alias, named
ic_action_heart.xml
, inres/drawable-hdpi-v21/
, pointing to@drawable/ic_action_heart_white
Have a drawable alias, named
ic_action_heart.xml
, inres/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.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.