Android drawable folders fallback rule - android

I'm trying to understand how the drawable folders in Android works. I found that in the resource folder in our project, it has the following folders:
res/drawable-ldpi/
res/drawable-ldpi-v8/
res/drawable-ldpi-v11/
res/drawable-mdpi/
res/drawable-mdpi-v8/
res/drawable-mdpi-v11/
res/drawable-hdpi/
res/drawable-hdpi-v8/
res/drawable-hdpi-v11/
res/drawable-xhdpi/
res/drawable-xhdpi-v8/
res/drawable-xhdpi-v11/
res/drawable-xxhdpi/
res/drawable-xxhdpi-v8/
res/drawable-xxhdpi-v11/
Can someone please educate me on how the fallback mechanism on these folders works? Also what does v8 and v11 mean?

From Android doc:
The API level supported by the device. For example, v1 for API level 1 (devices with Android 1.0 or higher) and v4 for API level 4 (devices with Android 1.6 or higher). See the Android API levels document for more information about these values.
-v8 and -v11 are API version but when android will determine the best match to use resource it will use them as "level" (and not strict api version number), e.g. with your project folders structure:
With device running Froyo (Android 2.2, API 8) with mdpi screen then resources will be taken from res/drawable-mdpi-v8/ folder
With device running Gingerbread (Android 2.3, API 10) with mdpi screen then resources will also be taken from res/drawable-mdpi-v8/ folder (because 8<10<11)
With device running Ice Cream Sandwich (Android 4.0, API 15) with mdpi screen then resources will also be taken from res/drawable-mdpi-v11/ folder (because 11<15)
--
Why default res folders are v-8, v-11,v-15... and not v-12,v-13 or v-16... ?
Because it was major releases of Android with changes on UI mechanism (e.g. Api 11 was the first Android optimized for tablets).

-v11 and -v8 are version qualifiers (you can read more here) for version 11 and 8 of android. If your app is running on one of them, then it tries to pick the drawable from the specific folder. If it is not in there, then it tries on the less specific. E.g. you are running and mdpi screen on Honeycomb, the first attempt is res/drawable-mdpi-v11/. If the drawable is not in there, it looks for it in res/drawable-mdpi/. The look up continues until the closest drawable to your configuration is found.

Related

Minimal API level 8 vs mipmaps

I need to support old devices (API 8) because app has users with Android 2.2. But our launcher icon looks awfully on new tablets that uses mip-map icons in the launcher.
Can I use mip-map on old devices (I understand that they doesn't support mip-map but can they recognize resources in the mip-map folder like drawables)?
If they can't then how can I setup build variant to build old version with drawable launcher icon and mip-map?

how android choose resource folders for different api levels

My app has layout-v21 folder for Android 5.0. Do API22 and API23 devices use layouts in this folder or the from the default layout folder?
How does Android choose API specific resources?
Do API22 and API23 devices use layouts in this folder
Yes, unless there is a layout-v22 or layout-v23 directory. layout-v21 says to use that directory for API Level 21 and higher.

How to include assets for xhdpi devices on Android 2.1 application?

I have a Android application using 2.1. I've gone ahead and created a drawable-xhdpi folder and put assets in it. I've set targetSdk=15, but the drawable in that folder is not being used. Is it not possible to support newer devices and keep an minimum sdk of 7?

Notification icons for android platforms 1.5 - 3.2

My app targets Android 1.5 to 3.2 and I'm making notification icons specific to those platforms. I'm finding it difficult to correctly to organize the icons for all these versions, including h/d/ldpi versions. I know in 3.2, the qualifiers changed, so I'm trying to account for this as well.
Currently, when I launcher in 3.2, it uses an icon for 2.3. My folder structure at the moment is as follows:
drawable
drawable-hdpi
drawable-hdpi-v9
drawable-ldpi-v9
drawable-mdpi-v11
drawable-mdpi-v9
drawable-v11
drawable-xlarge
Question is which folder (including any missing ones) should I put the platform & display/density specific icons in so I target 1.5 - 3.2 correctly?
You might try the Android Asset Studio for generating notification icons that follow conventions for different platform versions.

Android 2.1 bug: uses res/layout-v3 instead of res/layout

In addition to the general res/layout folder I have a res/layout-v3
folder for backward compatibility with Android 1.5, which has problems
with some RelativeLayout layouts.
It works perfectly with all phones and emulator versions tested so
far. Except of 2.1 (emulator and Nexus One). They choose to display
the Android 1.5 layout (res/layout-v3) instead of the default res/
layout.
Can anyone else confirm that? Is this an Android OS bug? If so, where
is the best place to submit the bug report?
UPDATE:
After reading up on https://developer.android.com/guide/practices/screens_support.html#qualifiers again (thanks Mark for the hint), especially this part
Resources that are for use only on a
specific API Level or higher. For
example, if your application is
designed to run on both Android 1.5
(API Level 3) and Android 1.6 (API
Level 4 and higher), you can use the
-v4 qualifier to tag any resources that should be excluded when your
application is running on Android 1.5
(API Level 3).
I changed my layout order from having
res/layout-v3 (for Android 1.5 only -> this was a wrong assumption I made)
res/layout (for anything else)
to my new configuration of having:
res/layout-v4 (for Android 1.6 and higher)
res/layout (for anything else -> in this case this would be Android 1.5 only)
If I understand the above documentation right and if my assumptions in the parentheses are correct this time it should work now. However, the result is the following:
Android 1.5 is using res/layout -> OK
Android 1.6 is using res/layout-v4 -> OK
Android 2.0 is using res/layout -> NOT OK
Android 2.1 is using res/layout-v4 -> OK
So why is Android 2.0 (on both Emulator and Motorola Milestone) not picking the right layout resource folder?
I tested it then again with 2.0.1 and it seems to work there. So that seems to be a bug in 2.0 which got fixed in 2.0.1
But now the weirdest thing: in order to make it somehow run on 2.0 I copied the res/layout-v4 folder to res/layout-v5 to force Android 2.0 using this layout resource. Didn't work. But then I tried copying it to res/layout-v6 (which is supposed to be Android 2.0.1) and voilĂ  all the sudden it works with 2.0. Very strange! But I hope this workaround will help a few other people out there.
I've tested several devices and emulators (although not very thoroughly), and it seems that the selected resource folder is the one with the higher version <= device version.

Categories

Resources