Resources
Resources are the additional files and static content that your code uses, such as bitmaps, user interface strings etc.
Each type of resource is placed in a specific subdirectory of your project's res/ directory.
You can add special qualifiers to resource directories to provide alternative resources for specific device configurations. At runtime, Android uses the appropriate resource based on the current configuration.
res/
--- drawable/
icon.png
background.png
--- drawable-mdpi/
icon.png
background.png
...
--- <resources_dir_name>-<qualifier>/
resource types
dir name | description |
---|---|
animator | XML files that define property animations. |
anim | XML files that define tween animations. Property animations can also be saved in this directory, but the animator directory is preferred for property animations to distinguish between the two types. |
color | XML files that define a state list of colors. |
drawable | Bitmap files (.png, .9.png, .jpg, .gif) or XML files that are compiled into Drawable subtypes. |
mipmap | Drawable files for different launcher icon densities. |
layout | XML files that define a user interface layout. |
menu | XML files that define app menus, such as an Options Menu, Context Menu, or Sub Menu. |
raw | Arbitrary files to save in their raw form, for example .mp3 files. As alternative you can put resources to /project/assets directory and read them with AssetManager. |
values | XML files that contain simple values, such as strings, integers, and colors. |
xml | Arbitrary XML files that can be read at runtime by calling Resources.getXML(). |
font | Font files with extensions such as .ttf, .otf, or .ttc, or XML files that include a <font-family> element. |
qualifiers
You can add multiple qualifiers to one directory name, by separating each qualifier with a dash. In this case, you must add them to the directory name in the order they are listed in the table.
configuration | description |
---|---|
MCC and MNC |
The mobile country code (MCC), optionally followed by mobile network code (MNC) from the SIM card in the device. For example, mcc310 is U.S. on any carrier, mcc310-mnc004 is U.S. on Verizon, and mcc208-mnc00 is France on Orange. |
language and region |
The language is defined by a two-letter ISO 639-1 language code, optionally followed by a two letter ISO 3166-1-alpha-2 region code. Android 7.0 (API 24) introduced support for BCP 47 language tags, which you can use to qualify language- and region-specific resources. To use a BCP 47 language tag, concatenate b+ and a two-letter ISO 639-1 language code, optionally followed by additional subtags separated by +. Examples:
If all your resources use a qualifier that is not correspond to current language, the system will not use them and your app will crash at runtime. For example, if all the string resources are Russian, and the device is in the English locale. |
Layout direction |
The layout direction of your app.
To enable right-to-left layout features for your app, you must set supportsRtl to "true" and set targetSdkVersion to 17 or higher in manifest file. |
Smallest width |
You can use this qualifier to ensure that, regardless of the screen's current orientation, your app's has at least N dps of width available for its UI. sw<N>dp Examples:
When your app provides multiple resource directories with different values for the smallestWidth qualifier, the system uses the one closest to the device's smallestWidth. Remember that the smallest device width does not change when the screen orientation is changed. |
Available width | Specifies a minimum available screen width, in dp units at which the resource should be used—defined by the N value. w<N>dp This configuration value changes when the orientation changes between landscape and portrait to match the current actual width. Examples:
|
Available height | Specifies a minimum available screen height, in dp units at which the resource should be used—defined by the N value. h<N>dp This configuration value changes when the orientation changes between landscape and portrait to match the current actual height. Examples:
|
Screen size |
Possible values:
If all your resources use a size qualifier that is larger than the current screen, the system will not use them and your app will crash at runtime. For example, if all layout resources are tagged with the xlarge qualifier, but the device is a normal-size screen. |
Screen aspect |
Possible values:
This isn't related to the screen orientation. |
Round screen |
Possible values (API 23+):
|
Wide color gamut |
Possible values (API 26+):
|
High Dynamic Range (HDR) |
Possible values (API 26+):
|
Screen orientation |
Current screen orientation, possible values:
|
UI mode |
Possible values:
|
Night mode |
Possible values:
|
Screen pixel density (dpi) |
Possible values:
There is a 3:4:6:8:12:16 scaling ratio between the six primary densities (ignoring the tvdpi density). So, a 9x9 bitmap in ldpi is 12x12 in mdpi, 18x18 in hdpi, 24x24 in xhdpi and so on. If you don't provide alternative resources with qualifiers that better match the current device configuration, the system may use whichever resources are the best match. |
Touchscreen type |
Possible values:
|
Keyboard availability |
Possible values:
This configuration value can change during the life of your application if the user opens the hardware keyboard. |
Primary text input method |
Possible values:
|
Navigation key availability |
Possible values:
|
Primary non-touch navigation method |
Possible values:
|
API level |
The API level supported by the device. Examples:
|