An important reason for external resources is Android Dynamic Resource selection mechanism.
Using the structure described below, you can create different resource values for the specified language, region, and hardware configurationAndroidThe system dynamically selects when running.
This allows you to create user interfaces for specific languages, regions, and hardware without changing yourCode.
In/ResSet a parallel folder under the folder to set the resources for selection, use"-"Delimiter to specify the applicationProgramSupported conditions.
The following hierarchical example shows the folder structure, including the default string value, the French string value, and the additional French string value for the Canadian region.
Project/
Res/
Values/
Strings. xml
Values-fr/
Strings. xml
Values-fr-RCA/
Strings. xml
The following list shows the identifiers you can use to customize the resource file name:
volumes language two lower-case ISO 639-1 language code (for example, en )
Bytes Region Lowercase" R ", Followed by two uppercase ISO 20176-1- α -2 Language code
(For example,Rus,RGB)
Bytes Screen direction " Port "( Portrait )," Land "( Landscape ),
"Square"(Square)
volumes screen pixel density pixel in 1 inch ( DPI ) (for example, 92 DPI , 108 DPI )
volumes touch screen type " notouch "," stylus "," finger "
volumes keyboard display " keysexposed "or" keyshidden "
BytesKeyboard Input type "Nokeys","Qwerty","12key"
Bytes UI Navigation type " Notouch "," DPAD "," Trackball "," Wheel "
BytesScreen Resolution Maximum screen size (pixels) (for example,320x240)
You can specify multiple identifiers for any resource type.-"Separator. Any combination is supported, but they must be used in the order given in the list, and each type of identifier cannot exceed1.
The following example showsDrawableValid and invalid folder names of resources.
Bytes Valid:
Drawable-en-Rus
Drawable-en-keyshidden
Drawable-land-notouch-nokeys-320x240
Bytes Invalid:
Drawable-Rus-en (Wrong order)
Drawable-Rus-ruk (A single type of identifier has multiple values)
WhenAndroidWhen a resource is obtained at runtime, it will find the most matched among the available resources. Starting from the list of folders (the folder contains the required values,AndroidSelect the folder with the most matching identifier. If the two folders match as many as possible, the matching identifiers in the above list are used as the basis for deciding the victory.