Android App Resources

Source: Internet
Author: User
Tags aliases

The main description of the Android project resource allocation situation

The more important points are:

1.Android resource file type and the corresponding relationship of the storage directory

2.Android detects the current device configuration and loads the appropriate resources for the application, so when you configure resources in the development process, you can differentiate between the resources required for different configuration devices based on the resource directory name, and the rules for directory names are the configuration qualifiers

3. Resource aliases can be used to implement the default configuration of resource sharing to other configuration qualifiers under the resource directory

Some usage requirements for resource aliases:

1. Objects that can be drawn
To create an alias that points to an existing drawing object, use the <bitmap> element. For example:

<? XML version= "1.0" encoding= "Utf-8" ?> <  xmlns:android= "http://schemas.android.com/apk/res/android"    android:src = "@drawable/icon_ca" />

2 layout
To create an alias that points to an existing layout, use the <include> element that is wrapped in <merge>. For example:

<? XML version= "1.0" encoding= "Utf-8" ?> < Merge >    <  layout= "@layout/main_ltr"/></merge  >

In addition to the above two special resource types, others can be used to point to the target resource directly in the form of the @ type/id_name.

In the case of multiple sets of configuration resources, how does Android find the most appropriate resource:

Steps:

1. Resource directory with qualifiers for excluding and conflicting device information

2. Get information about the configuration qualifier in the device information (based on the precedence of the configuration qualifier in the following order)

3. Determine if the resource configuration for the application contains the resource qualifier obtained by Step 2, and do not repeat step 2 to get the resource configuration qualifier for the next priority, or to perform step 4

4. Exclude a resource configuration that does not match, that is, a resource folder that matches the resource qualifier

5. Repeat steps 2, 3, 4 until the remaining set of resources

Simply put, by configuring the precedence of the qualifier table, matching each other to constantly exclude the relevant resource folders that do not conform to the device information, to the end there are only two cases, 1. Only the default resource configuration qualifier directory, or no resource directory has a match to the resource qualifier, 2. Filter out the most compliant resource directories according to the qualifier table

The following table is the default folder name for the resource:

Catalogue Resource Type
animator/ An XML file that is used to define property animations.
anim/ The XML file that defines the gradient animation. (Property animations can also be saved in this directory, but in order to differentiate between the two types, the property animation preferred animator/ directory.) )
color/ An XML file that defines a list of color states. See Color Status List resources
drawable/

A bitmap file (,,, .png .9.png ), .jpg .gif or an XML file that is compiled as the following to draw the object resource subtype:

  • Bitmap file
  • Nine Gongge (resizable bitmap)
  • Status list
  • Shape
  • Animate to draw an object
  • Other objects that can be drawn

See Drawing an object resource.

mipmap/ A drawing object file that is suitable for different launcher icon densities. For more information about using mipmap/ the folder Management Launcher icon, see Manage Project Overview.
layout/ An XML file that defines the layout of the user interface. See Layout resources.
menu/ An XML file that defines an application menu, such as a menu of options, a context menu, or a submenu. See Menu resources.
raw/

Any file that you want to save in its original form. To open these resources using the original InputStream , use the resource ID (that is, R.raw. FileName ) calls Resources.openrawresource () .

However, if you want to access the original file name and file hierarchy, you might consider saving some resources under the assets/ directory (instead of res/raw/). The files in assets/ do not have resource IDs, so you can only use Assetmanager to read these files.

values/

An XML file that contains simple values such as strings, integers, and colors.

An res/ XML resource file in another subdirectory defines a single resource based on the XML file name, and values/ the files in the directory can describe multiple resources. For files in this directory, <resources> each child element of the element defines a resource. For example, an <string> element creates R.string a resource, and an <color> element creates a R.color resource.

Because each resource is defined with its own XML element, you can name the file according to your needs and place different resource types in one file. However, for clarity, you may want to place unique resource types in separate files. For example, for resources that can be created in this directory, the corresponding file name conventions are given below:

  • Arrays.xml, used for resource arrays (typed arrays).
  • Colors.xml: Color value.
  • Dimens.xml: Dimension value.
  • Strings.xml: String value.
  • Styles.xml: Style.

See string resources, style resources, and more resource types.

xml/ Any XML file that can be read by a call at run time Resources.getXML() . Various XML configuration files, such as searchable configurations, must be saved here.

The following table is a list of configuration qualifiers:

Configuration Qualifier Value Description
MCC and MNC example:
mcc310
mcc310-mnc004
MCC208-MNC00
and so on

Mobile Country Code (MCC), followed by the mobile Network Code (MNC) in the device SIM card. For example, mcc310 refers to any carrier in the United States, and mcc310-mnc004 refers to Verizon in the United States, and mcc208-mnc00 refers to the French Orange Company.

If the device uses a radio connection (GSM phone), the MCC and MNC values are from the SIM card. The

can also use the MCC separately (for example, to include country-specific legitimate resources in the app). If you only need to specify by language, use the language and region qualifier (described later). If you decide to use the MCC and MNC qualifiers, do so with caution and test that the qualifier works as expected.

See also configuration fields MCC and MNC , which represent the current mobile country code and the mobile network code, respectively.

language and region Example:
en
fr
En-rus
fr-rfr
fr-rca
et cetera

Language is defined by a two-letter Iso639-1 language code, You can select a Iso3166-1-alpha-2 area code that is followed by two letters (with the lowercase letter " R " in front).

The code is not case-sensitive, and the r prefix is used to differentiate the region code. You cannot specify a zone individually.

If the user changes the language in the system settings, it may change in the app life cycle. For information on what impact this will have on your app during runtime, see Handling runtime changes.

For a complete guide to localizing your app for other languages, see localization.

See also the locale configuration field, which represents the current locale.

Layout direction ldrtl
ldltr

The layout direction of the app. ldrtlmeans "layout direction right to left". ldltrmeans "layout direction left to right", which is the default implicit value.

It applies to any resource, such as layouts, pictures, or values.

For example, to provide a specific layout for Arabic, and to provide a common layout for any other right-to-left language, such as Persian or Hebrew, you can encode the following:

res/    layout/           main.xml  (Default layout)    layout-ar/          main.xml  ( Specific layout for Arabic)    layout-ldrtl/          main.xml  (any "right-to-left" language, except                  for Arabic, because the "AR" language qualifier have                  a higher precedence.)  

Note : To enable right-to-left layout features for your app, you must supportsRtl set "true" it to, and set it to targetSdkVersion 17 or later.

This entry is a new configuration in API level 17.

Smallestwidth sw<N>dp

Example:
sw320dp
sw600dp
sw720dp
Wait a minute

The basic size of the screen, specified by the minimum size of the available screen area. Specifically, the smallestwidth of the device is the minimum size of the available height and width of the screen (you can also treat it as the "minimum possible width" of the screen). You can use this qualifier to ensure that the available width of the app UI is at least DP, regardless of the current orientation of the screen <N> .

For example, if the layout requires that the minimum size of the screen area is always at least 600DP, you can use this qualifier to create a layout resource res/layout-sw600dp/ . These resources are used only when the minimum size of the available screen is at least 600DP, regardless of whether the edge represented by 600DP is the height or width that the user considers. Smallestwidth is the fixed screen size feature of the device, and the smallestwidth of the device does not change with the screen orientation .

The smallestwidth of the device takes into account the screen decoration elements and the system UI. For example, if there are some persistent UI elements on the device's screen that occupy space along the smallestwidth axis, the system declares that Smallestwidth is less than the actual screen size because these screen pixels are not available for your UI. Therefore, the value used should be the actual minimum size required by the layout (typically, this value is the "minimum width" supported by the layout, regardless of the current orientation of the screen).

Here are some values that you can use for normal screen sizes:

    • 320, for devices with the following screen configuration:
      • 240x320 ldpi (QVGA Mobile)
      • 320x480 mdpi (MOBILE)
      • 480x800 hdpi (High density mobile)
    • 480, for screens such as 480x800 mdpi (tablet/mobile).
    • 600, for screens such as 600x1024 mdpi (7-inch Tablet PC).
    • 720, for screens such as 720x1280 mdpi (10-inch Tablet PC).

When an app provides different smallestwidth qualifier values for multiple resource catalogs, the system uses the values that are closest (but not exceeded) to the device smallestwidth.

This entry is a new configuration in API level 13.

See also android:requiresSmallestWidthDp properties and smallestScreenWidthDp configuration fields, which declare a minimum smallestwidth that is compatible with the application, which stores the smallestwidth value of the device.

For more information about designing different screens and using this qualifier, see the support for multiple screen developer guides.

available width w<n>dp

Example:
w720dp
W1024DP
and so on

Specifies the minimum available screen width that the resource should use, in DP , as defined by the <n> value. When you switch between landscape and portrait, this configuration value changes to match the current actual width. When the

App provides different values for this configuration for multiple resource catalogs, the system uses values that are closest (but not exceeded) to the current screen width of the device. The values here take into account the screen decoration elements, so if there are persistent UI elements on the left or right edge of the device display, it will use a width value smaller than the actual screen size, which will reduce the available space for the app.

This entry is a new configuration in API level 13.

See also screenwidthdp configuration field, which holds the current screen width.

For more information about designing different screens and using this qualifier, see the support for multiple screen developer guides.

Available height h<N>dp

Example:
h720dp
h1024dp
Wait a minute

Specifies the minimum available screen height that the resource should use, in "DP", defined by the <N> value. When switching between landscape and portrait, this configuration value also changes to match the current actual height.

When an app provides a different value for this configuration for multiple resource catalogs, the system uses a value that is closest (but not exceeded) the current screen height of the device. The values here take into account the screen decoration elements, so if there are persistent UI elements on the top or bottom edge of the device display, taking into account these UI elements, and to reduce the available space for the app, it will use a height value smaller than the actual screen size. A non-fixed screen decoration element (for example, a mobile phone status bar that can be hidden in full screen) is not within the scope of consideration, and the window decorations such as the title bar or action bar are not considered, so the application must be prepared to handle spaces that are slightly smaller than the values specified.

This entry is a new configuration in API level 13.

See also screenHeightDp Configure a field, which holds the current screen width.

For more information about designing different screens and using this qualifier, see the support for multiple screen developer guides.

Screen size small
normal
large
xlarge
  • small : A screen that is similar in size to a low-density QVGA screen. The minimum layout size of the small screen is approximately 320x426 DP units. For example, QVGA low-density screens and VGA high-density screens.
  • Normal : A screen that is similar in size to a medium-density HVGA screen. The minimum layout size of the standard screen is approximately 320x470 DP units. For example, WQVGA low-density screens, HVGA medium-density screens, and WVGA high-density screens.
  • Large : A screen that is similar in size to a medium-density VGA screen. The minimum layout size of the large screen is approximately 480x640 DP units. For example, VGA and WVGA medium density screens.
  • xlarge : A screen that is significantly larger than the traditional medium-density HVGA screen. The smallest layout size of the oversized screen is approximately 720x960 DP units. In most cases, the large screen size of the device is too large to fit into the pocket, the most common is the flat-panel device. the new configuration in API Level 9.

note : Using a dimension qualifier does not mean that the resource applies only to the screen of that dimension. If you do not provide a qualifier that best matches the current device configuration for the standby resource, the system may use the most matching resource.

note : If all resources use a size qualifier greater than the current screen, the system does not use these resources, and the app will crash at run time (for example, If all layout resources are marked with the XLarge qualifier, the device is a standard-sized screen.

This entry is a new configuration in API level 4.

For more information, see Support for multiple screens.

See also the screenlayout configuration field, which indicates whether the screen is small, standard, or large.

Screen aspect ratio long
notlong
  • long: widescreen, such as WQVGA, WVGA, FWVGA
  • notlong: Non-widescreen, such as QVGA, HVGA, and VGA

This entry is a new configuration in API level 4.

It is completely based on the aspect ratio (widescreen width) of the screen, regardless of the orientation of the screen.

See also screenLayout configuration field, which indicates whether the screen is widescreen.

Circular screen round
notround
  • round: circular screen, e.g. round wearable device
  • notround: a square screen, such as a phone or tablet

This entry is a new configuration in API level 23.

See also the isScreenRound() configuration method, which indicates whether the screen is widescreen.

screen orientation Port
Land
  • Port : Device is in portrait (vertical)
  • land : Device is in landscape (horizontal)

If the user rotates the screen, it may change in the app life cycle 。 For information on what impact this will have on your app during runtime, see Handling runtime changes.

See also the Orientation configuration field, which indicates the current device orientation.

UI mode car
desk
television
Appliance Watch
  • car : Device is displayed on the mobile phone holder
  • desk : device is displaying on desktop phone seat
  • Television : devices are being displayed on TV, providing users with a "10-foot" experience with UI located on a large screen away from the user, primarily for directional keys or other non-pointer interactions
  • Appliance : Device as a device without display
  • Watch : The device is equipped with a display, worn on the wrist

This is a new configuration in API Level 8, a new TV configuration in API 13, and a new watch configuration in API 20.

To learn how the app responds when the device is plugged in or removed from the phone, read identify and monitor the docking status and type.

If a user puts the device into a phone seat, it may change in the app lifecycle. You can use Uimodemanager to enable or disable some of these modes. For information on what impact this will have on your app during runtime, see Handling runtime changes.

Night mode night
notnight
  • night: Night
  • notnight: Daytime

This entry is a new configuration in API Level 8.

If the night mode stays in automatic mode (the default), it may change in the app life cycle. In this case, the pattern is adjusted according to the time of day. You can use UiModeManager enable or disable this mode. For information on what impact this will have on your app during runtime, see Handling runtime changes.

Screen pixel density (dpi) ldpi
mdpi
hdpi
xhdpi
xxhdpi
xxxhdpi
nodpi
tvdpi
anydpi
    • ldpi: Low-density screen, approx. 120dpi.
    • mdpi: Medium density (traditional HVGA) screen; approx. 160dpi.
    • hdpi: High-density screen, approx. 240dpi.
    • xhdpi: Ultra-high-density screen, approx. 320dpi. This entry is a new configuration in API Level 8
    • xxhdpi: Ultra-high-density screen, approx. 480dpi. This entry is a new configuration in API level 16
    • xxxhdpi: Ultra Ultra-high-density screen usage (launcher icon only, see comments in "Support multiple screens"); approximately 640dpi. This entry is a new configuration in API level 18
    • nodpi: It can be used for bitmap resources that you do not want to scale to match device density.
    • tvdpi: A screen with a density between mdpi and hdpi; about 213dpi. It is not a "primary" density group, primarily for television, and most applications do not need it. For most applications, providing MDPI and hdpi resources is sufficient and the system will scale as needed. This entry is a new configuration in API level 13
    • anydpi: This qualifier is suitable for all screen densities with a higher precedence than other qualifiers. This can be useful for vector-drawn objects. This entry is a new configuration in API level 21

The scaling ratio between the six primary densities is 3:4:6:8:12:16 (ignoring tvdpi density). Therefore, 9x9 (ldpi) bitmaps are equivalent to 12x12 (MDPI), 18x18 (hdpi), 24x24 (xhdpi) bitmaps, and so on.

If you think that image resources are not performing well on TV or some other device, and you want to try using tvdpi resources, the scale is 1.33*mdpi. For example, the 100px x 100px image of the mdpi screen should be equivalent to tvdpi 133px x 133px.

Note : Using the density qualifier does not indicate that the resource applies only to the screen of that density. If you do not provide a qualifier that best matches the current device configuration for the standby resource, the system may use the most matching resource.

For more information about how to handle different screen densities and how Android scales bitmaps to fit the current density, see support for multiple screens.

Touch screen Type notouch
finger
  • notouch: The device does not have a touch screen.
  • finger: The device has a touchscreen that is designed for users to interact directly with their fingers.

See also touchscreen configuration field, which indicates the type of touch screen on the device.

keyboard availability keysexposed
keyshidden
Keyssoft
  • keysexposed : The device has a keyboard available. If the device has a soft keyboard enabled (not to be possible), this qualifier can be used even if the hard keyboard is not displayed to the user, even if the device does not have a hard keyboard. If the soft keyboard is not provided or disabled, this qualifier is used only when the hard keyboard is displayed.
  • Keyshidden : The device has a hard keyboard available, but it is hidden and the device does not have a soft keyboard enabled.
  • keyssoft : The device has a soft keyboard enabled (whether or not it is visible).

If a keysexposed resource is provided, but the Keyssoft resource is not provided, the keysexposed is used as long as the system has a soft keyboard enabled resources Regardless of whether the keyboard is visible.

If a user opens a hard keyboard, it may change in the app life cycle. For information on what impact this will have on your app during runtime, see Handling runtime changes.

See also configuration fields Hardkeyboardhidden and Keyboardhidden , which indicate the visibility of the hard keyboard and the visibility of any one keyboard, including the soft keyboard, respectively.

Main text Input Method nokeys
qwerty
12key
  • nokeys: The device does not have a hard key for text input.
  • qwerty: The device has a standard hard keyboard, whether visible to the user or not.
  • 12key: The device has a 12-key hard keyboard (whether visible to the user or not).

See also keyboard configuration field, which indicates the main text input method available.

Navigation key Availability navexposed
navhidden
  • navexposed: The navigation key is available to the user.
  • navhidden: The navigation key is not available (for example, behind a sealed lid).

If the user displays a navigation key, it may change in the app life cycle. For information on what impact this will have on your app during runtime, see Handling runtime changes.

See also navigationHidden configuration field, which indicates whether the navigation key is hidden.

Main non-touch navigation methods nonav
dpad
trackball
wheel
  • nonav: In addition to using the touchscreen, the device has no other navigational facilities.
  • dpad: The device has a directional key for navigation.
  • trackball: The device has a trackball for navigation.
  • wheel: The device has a steering wheel for navigation (uncommon).

See also navigation configuration field, which indicates the type of navigation method available.

Platform version (API level) Example:
v3
v4
v7
Wait a minute

The API level supported by the device. For example, for v1 API Level 1 (Devices with an Android 1.0 or later system), v4 corresponding to API level 4 (Devices with Android1.6 or later systems). For more information about these values, see the Android API level documentation.

Android App Resources

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.