hhg
hhg

Reputation: 687

customizing a drawable for a range of APIs Android

I'd like to customize one drawable e.g. /drawable/image.png

only for APis 19 to 21. For later APIs (after 22 incl. I'd like a drawable to be different). Do I need to create directories drawable-v19, drawable-v20, drawable-v21, drawable-v22 (for the others?) ? It's a bit unclear to me how it works...

Upvotes: 8

Views: 4520

Answers (2)

lluchmk
lluchmk

Reputation: 440

You should only need to create directories for the versions that set a different resource. So your resources directory would look something like:

res/
    drawable/        --> SDK version below 19
        image.png
    drawable-v19/    --> SDK version between 19 and 21 (including both)
        image.png
    drawable-v22/    --> SDK version 22 and greater
        image.png

Edit: Seems to be working this way. I've set up a small project with strings.xml for sdk 19 and 22, launched two emulators, with sdk 21 and 25. The SDK 21 one showed the string in the v19 strings, and the SDK 25 the one in v22 strings. Here's a pic with the results:Andoroir version qualifires

Hope it helps. (Couldn't test it with sdk lower than 19, but that should take values from the default file, since no qualifier applies.)

Upvotes: 19

user2695433
user2695433

Reputation: 2163

You can create drawable folders like drawable-v19, drawable-v20, drawable-v21, drawable-v22 for each custom images for each versions. If the app is running on one of these devices it picks from these matching version custom respective folders or else falls back to the generic drawable folder.

Upvotes: 0

Related Questions