One, color resources
1. color XML file format
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>//resources root element
<color name= "" > #000000 </color>
Color child element
</resouces>
2. Reference format:
Java code: R.color.color_name (This is an int-type data that represents the address of a resource)
XML file: @color/color_name
3, obtain the color value method Getresources (). GetColor (); Returns a color value similar to #0000ff
Second, string resources
1. xml file format
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>//resources root element
<string name= "" >StringHere</string>
String child element
</resouces>
2. Reference format
Java code: R.string.string_name
XML file: @string/string_name
3, the method of obtaining the string: resources.getstring (int); Returns an object of type string
Note that both methods settext (int resid) and settext (String string_name) are allowed in the control
Third, the size of resources
1. xml file:
Copy Code code as follows:
<dimen name=dimen_name> dimen_value</dimen>
The unit of dimension value can be px (pixel) or mm (mm, actual screen size) or DP
2. Reference format
Java code: R.dimen.dimen_name
XML file: @dimen/dimen_name
3, Resources.getdimension (r.dimen.dimen_name);
Note Using this method returns a float-type value, and the SetWidth () parameter is generally required to be of type int, so a forced type conversion is done.
Iv. XML resource files
1. xml file:
Android's own XML file is usually placed in the Values/xml/xml_name.xml, where a new XML file needs to be built using the new->file bed;
version of the XML file
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
2, Java code in the R.xml.xml_name
3, resources.getxml (int resid); Returns a Xmlresourceparser object