Google recommends that we isolate resources from the code when developing Android applications so that we maintain them separately. With a separate resource design, we can also provide optional resources to support specific device configurations such as different languages or screen sizes, which becomes increasingly important as more and more Android devices are available in different configurations. In order to provide compatibility for different configurations, you must organize resources in the res/directory of your project. Different subdirectories are used, by type and by configuration.
For any type of resource, you can provide a default and multiple optional resources for your application:
- The default resource is the resource that is used whenever you configure me to force or not meet the configured optional resources.
- An optional resource is a resource that is provided for use by a specific configuration. We provide a configuration qualifier for the Res's self-folder name, which associates a specific configuration with a specific optional resource. ("Note" Therefore, this is a highly discrete resource configuration, we are not in the code through the If...else and other conditional statements to determine which optional resources to use, but by one of the system's services to automatically determine the current configuration and resource folder name to load the appropriate resources)
1. Resource type:
Directory |
Resource Type |
animator/ |
XML files that define property animations. |
anim/ |
XML files that define tween animations. (Property animations can also are saved in this directory, but the animator/ directory is preferred for property animations to Distinguish between the types.) |
color/ |
XML files that define a state list of colors. See Color State List Resource |
drawable/ |
Bitmap files (,, .png .9.png .jpg , .gif ) or XML files that is compiled into the following drawable resource subtypes:
- Bitmap files
- Nine-patches (re-sizable bitmaps)
- State lists
- Shapes
- Animation Drawables
- Other Drawables
See Drawable Resources. |
mipmap/ |
drawable files for different launcher icon densities. For more information in managing Launcher icons mipmap/ with folders, see Managing Projects Overview. |
layout/ |
XML files that define a user interface layout. See Layout Resource. |
menu/ |
XML files that define application menus, such as an Options menu, Context menu, or Sub menu. See Menu Resource. |
raw/ |
Arbitrary files to the save in their raw form. To open these resources with a raw InputStream , call Resources.openRawResource() with the resource ID, which is R.raw.filename . However, if you need access to original file names and file hierarchy, you might consider saving some resources in the directory (instead of res/raw/ ). Files in is not assets/ given a resource ID and so can read them only using AssetManager . |
values/ |
XML files that contain simple values, such as strings, integers, and colors. Whereas XML resource files in and res/ subdirectories define a single resource based on the XML filename, files in the values/ directory describe multiple resources. For a file in this directory, each child of the <resources> element defines a single resource. For example, the A <string> element creates an R.string resource and a <color> element creates an R.color resource. Because each resource are defined with their own XML element, you can name the file whatever you want and place different res Ource types in one file. However, for clarity, your might want to place unique resource types in different files. For example, here is some filename conventions for resources you can create in this directory:
- Arrays.xml for resource arrays (typed arrays).
- Colors.xml for color values
- Dimens.xml for dimension values.
- Strings.xml for string values.
- Styles.xml for Styles.
See String Resources, Style Resource, and more Resource Types. |
xml/ |
Arbitrary XML files that can is read at runtime by calling Resources.getXML() . Various XML configuration files must is saved here, such as a searchable configuration. |
2, Resource expression: 3, Resource application: 4, the specific resource type introduction:
[Android] App resource (app resources)