From ff339f0b966c5ca62867689a13ea713e6cb62a15 Mon Sep 17 00:00:00 2001
From: Katarina Stenstedt
zv@O1`Zzz_7jGxfbOd@!xsD
@ZkHXq3K~qM_
Resources are externalized from source code, and XML files are compiled into -a binary, fast loading format for efficiency reasons. Strings, likewise are compressed +a binary, fast loading format for efficiency reasons. Strings, likewise, are compressed into a more efficient storage form. It is for these reasons that we have these different resource types in the Android platform.
@@ -88,12 +88,12 @@ of any XML files.You will create and store your resource files under the appropriate
subdirectory under the res/ directory in your project. Android
has a resource compiler (aapt) that compiles resources according to which
-subfolder they are in, and the format of the file. Here is a list of the file
+subfolder they are in, and the format of the file. Table 1 shows a list of the file
types for each resource. See the
Available Resources for
descriptions of each type of object, the syntax, and the format or syntax of
the containing file.
Table 1
| Directory | @@ -410,7 +410,7 @@ public class MyActivity extends Activity
|---|
| Qualifier | Values | |
|---|---|---|
| Language | -The two letter ISO
- 639-1 language code in lowercase. For example:
- en, fr, es |
- MCC and MNC | +The mobile country code and mobile network code from the SIM in the device. For example mcc310-mnc004 (U.S., Verizon brand); mcc208-mnc00 (France, Orange brand); mcc234-mnc00 (U.K., BT brand). + + If the device uses a radio connection (GSM phone), the MCC will come from the SIM, and the MNC will come from the network to which the device is attached. You might sometimes use the MCC alone, for example to include country-specific legal resources in your application. If your application specifies resources for a MCC/MNC combination, those resources can only be used if both the MCC and the MNC match. |
+
| Region | -The two letter
- ISO
- 3166-1-alpha-2 language code in uppercase preceded by a lowercase
- "r". For example: rUS, rFR, rES |
- Language and region | +The two letter ISO
+ 639-1 language code and two letter
+ ISO
+ 3166-1-alpha-2 region code (preceded by lowercase "r"). For example
+ en-rUS, fr-rFR, es-rES. + + The codes are case-sensitive: The language code is lowercase, and the country code is uppercase. You cannot specify a region alone, but you can specify a language alone, for example en, fr, es. |
+
| Screen orientation | port, land, square |
|
| Screen pixel density | -92dpi, 108dpi, etc. |
- 92dpi, 108dpi, etc. When Android selects which resource files to use, it handles screen density differently than the other qualifiers. In step 1 of How Android finds the best matching directory (below), screen density is always considered to be a match. In step 4, if the qualifier being considered is screen density, Android will select the best final match at that point, without any need to move on to step 5. |
+
| Touchscreen type | notouch, stylus, finger |
|
| Whether the keyboard is available to the user | -keysexposed, keyshidden |
- keysexposed, keyshidden, keyssoft + If your application has specific resources that should only be used with a soft keyboard, use the keyssoft value. If no keyssoft resources are available (only keysexposed and keyshidden) and the device shows a soft keyboard, the system will use keysexposed resources. |
+
| Primary text input method | nokeys, qwerty, 12key |
@@ -506,6 +510,14 @@ MyApp/
320x240, 640x480, etc. The larger dimension
must be specified first. |
| SDK version | +The SDK version supported by the device, for example v3. The Android 1.0 SDK is v1, the 1.1 SDK is v2, and the 1.5 SDK is v3. |
+ |
| (Minor version) | +(You cannot currently specify minor version. It is always set to 0.) | +
This list does not include device-specific parameters such as carrier, @@ -513,92 +525,84 @@ branding, device/hardware, or manufacturer. Everything that an application needs to know about the device that it is running on is encoded via the resource qualifiers in the table above.
-Here are some general guidelines on qualified resource directory names:
+All resource directories, qualified and unqualified, live under the res/ folder. Here are some guidelines on qualified resource directory names:
drawable directory must be named
- drawable-port, not drawable-PORT.drawable-port
- and drawable-PORT, even if you had intended "port" and
- "PORT" to refer to different parameter values.drawable-rEN-rFR/)drawable-en-rUS-land will apply to landscape view,
- US-English devices. res/ folder.
- Qualified directories cannot be nested (you cannot have res/drawable/drawable-en) MyApp/res/drawable-port-92dp/myimage.pngR.drawable.myimage (code)@drawable/myimage (XML)drawable-en-rUS-land will apply to US-English
+ devices in landscape orientation. values-mcc460-nokeys/values-nokeys-mcc460/drawable directory must be named
+ drawable-port, not drawable-PORT or drawable-Port.drawable-rES/ and drawable-rFR/, containing identical files. You cannot
+ have a directory named drawable-rES-rFR/. res/drawable/drawable-en. All resources will be referenced in code or resource reference syntax by
+ their simple, undecorated names. So if a resource were named this:
+ MyApp/res/drawable-port-92dpi/myimage.png
+ It would be referenced as this:
+ R.drawable.myimage (code)
+ @drawable/myimage (XML)
If several drawable directories are available, Android will select one of them (as described below) and load myimage.png from it.
Android will pick which of the various underlying resource files should be -used at runtime, depending on the current configuration. The selection process -is as follows:
- +used at runtime, depending on the current configuration of the device. The example used here assumes the following device configuration: +++Locale =
+en-GB
+ Screen orientation =port
+ Screen pixel density =108dpi
+ Touchscreen type =notouch
+ Primary text input method =12key
+
Here is how Android makes the selection:
MyApp/res/drawable-port-92dpi/.
- ---MyApp/res/drawable/myimage.png -MyApp/res/drawable-en/myimage.png -MyApp/res/drawable-port/myimage.png --MyApp/res/drawable-port-92dpi/myimage.png-
MyApp/res/drawable-en/ and MyApp/res/drawable-port/.
- The directory MyApp/res/drawable/ is eliminated because
- it has zero matching configurations, while the others have one matching
- configuration.
- ----MyApp/res/drawable/myimage.png-MyApp/res/drawable-en/myimage.png -MyApp/res/drawable-port/myimage.png -
MyApp/res/drawable-en/.
- --MyApp/res/drawable-en/myimage.png --MyApp/res/drawable-port/myimage.png-
drawable-fr-rCA/ directory will be eliminated, because it contradicts the locale of the device.MyApp/res/drawable/ +MyApp/res/drawable-en/ ++ Exception: Screen pixel density is the one qualifier that is not used to eliminate files. Even though the screen density of the device is 108 dpi,MyApp/res/drawable-fr-rCA/+MyApp/res/drawable-en-port/ +MyApp/res/drawable-en-notouch-12key/ +MyApp/res/drawable-port-92dpi/ +MyApp/res/drawable-port-notouch-12key
drawable-port-92dpi/ is not eliminated from the list, because every screen density is considered to be a
+ match at this point.
+ + Exception: If the qualifier in question is screen pixel density, Android will select the option that most closely matches the device, and the selection process will be complete. In general, Android will prefer scaling down a larger original image to scaling up a smaller original image.MyApp/res/drawable/+MyApp/res/drawable-en/ +MyApp/res/drawable-en-port/ +MyApp/res/drawable-en-notouch-12key/ +MyApp/res/drawable-port-92dpi/+MyApp/res/drawable-port-notouch-12key
+ Only one choice remains, so that's it. When drawables are called for in this example application, the Android system will load resources from theMyApp/res/drawable-en/+MyApp/res/drawable-en-port/ +MyApp/res/drawable-en-notouch-12key/
MyApp/res/drawable-en-port/ directory.
Tip: The precedence of the qualifiers is more important than the number of qualifiers that exactly match the device. For example, in step 4 above, the last choice on the list includes three qualifiers that exactly match the device (orientation, touchscreen type, and input method), while drawable-en has only one parameter that matches (language). However, language has a higher precedence, so drawable-port-notouch-12key is out.
This flowchart summarizes how Android selects resource directories to load.
+
The resource system brings a number of different pieces together to form the final complete resource functionality. To help understand the overall system, here are some brief definitions of the core concepts and @@ -671,7 +675,7 @@ information is applied as approriate) and load them into its instance.
Configuration: For any particular resource identifier, there may be multiple different available values depending on the current configuration. The configuration includes the locale (language and country), screen -orientation, screen density, etc. The current configuration is used to +orientation, etc. The current configuration is used to select which resource values are in effect when the resource table is loaded.
@@ -710,4 +714,3 @@ SDK matures, this section will contain information on the Internationalization and Localization features of the Android platform. In the meantime, it is a good idea to start by externalizing all strings, and practicing good structure in creating and using resources. -