Cruces
Cruces

Reputation: 3119

How can you use different properties in android xml files according to api version?

I am creating a project that uses a big number of icons, in order to support multiple screens easily, I created the icons using vector graphics (SVG paths I believe they are called) which worked ok in my device.

Unfortunately when I tried to use it on older devices (anything with android less than 5.0) I get an inflater exception.

After searching I found out that in order to use vector graphics for those devices instead of using

android:src

I have to use

app:srcCompat

this indeed fixed the problem, but now when I deploy it to a newer device, the icons won't show (at least it doesn't crash though, so that's something)

Is there a way to define some sort of style to use according to api version

so that I can do something along the lines of :

<style name="android.api.21">
    <item name="android:src">ic_menu</item>
</style>

<style name="android.api.19">
    <item name="app:srcCompat">ic_menu</item>
</style>

Thanks in advance for any help you can provide

Upvotes: 1

Views: 139

Answers (1)

Alex
Alex

Reputation: 616

Just use the same style name (for example, styles.xml) and in resources folder (app/main/res) create different folders with naming values (common version), values-v21 (for API 21, Lolipop 5.0), values-v19 (API 19, KitKat 4.4) and so on and so forth.

Upvotes: 2

Related Questions