For Android, resource references are managed through specific configuration files, which facilitates resource unification, integration, and calling. In Android, not only images and audios are resources, but strings are also managed as resources. The Android operating system uses XML files to associate these resources for unified management.
6.1 type of resources
|
Resource Type |
Required directory |
File Name |
XML tag |
|
String |
/RES/values/ |
Strings. xml |
<String> |
|
Plural string |
/RES/values/ |
Strings. xml |
<Plurals>, <item> |
|
String Array |
/RES/values/ |
Strings. xml |
<String-array>
<Item> |
|
Boolean |
/RES/values/ |
Bools. xml |
<Bool> |
|
Color |
/RES/values/ |
Colors. xml |
<Color> |
|
Color status table |
/RES/color/ |
This type of file is generally used to describe changes in the component status. |
<Selector>
<Item> |
|
Dimensions |
/RES/values/ |
Dimens. xml |
<Dimen> |
|
Integer |
/RES/values/ |
Integers. xml |
<Integer> |
|
Integer Array |
/RES/values/ |
Integers. xml |
<Integer-array>
<Item> |
|
Hybrid Array |
/RES/values/ |
Arrays. xml |
<Array>, <item> |
|
Simple drawable graphics |
/RES/values/ |
Drawables. xml |
<Drawable> |
|
Image |
/RES/drawable/ |
The file name of a single image. The name is determined based on your own needs. |
Supported image file names |
|
Compensation Animation |
/RES/anim/ |
Customized as needed |
<Set>, <alpha>,
<Scale>, <translate>,
<Rotate> |
|
Frame-by-frame animation |
/RES/drawable/ |
Customized as needed |
<Animaton-List>,
<Item> |
|
Menu |
/RES/menu/ |
Customized as needed |
<Menu> |
|
XML file |
/RES/XML/ |
Customized as needed |
Custom |
|
Original file |
/RES/raw/ |
Custom |
Custom |
|
Layout |
/RES/layout/ |
Main. XML, etc. |
Multiple types, layout Definition |
|
Style and topic |
/RES/values/ |
Styles. XML, themes. xml |
<Style> |
Table 6.1.1 Resource Type table
Note: all these files are managed through R. java, once a path in these files is incorrect, it may cause R. java file generation error, cannot generate R. java file. This is why some people may fail to find the R. Class.
In addition, the directory must be specific because the Resource Name inherits from the file name of the specific resource.
6.2 Java Resource Access
You can use the getresources () method to directly access resources using Java code.
6.3 use resources
In addition to common resource usage, as mentioned in the above 6.2, strings can be modified in HTML mode when resources are used in XML, especially string resources. For example, <B>, <I>, and <u> can be used to bold, italic, and underline strings.
In addition to the above usage, you can also create formatted strings, but you need to escape them when you need to bold, italic, and underline.
For example:
<String
Name ="Testword"> Hello world! The year
& Lt; U & gt; % 1 $ D & lt;/u & gt; and the month
& Lt; U & gt; % 2 $ D & lt;/u & gt ;! I \'m
& Lt; I & gt; % 3 $ S & lt;/I & gt;. </string>
Note: If you want to convert them to normal text, you also need to convert the returned strings through HTML. fromhtml.
The usage of other resources is similar, so we will not detail them here. It will be involved later.
Conclusion 6.4
Summarizes some general resource references, which are described in subsequent chapters.