Android resource file--values folder file and usage
The following files are in the Values folder. For example: full path: Res/values/string.xml.
The i>strings.xml file, which defines some string variables and arrays that need to be used in development, is used to internationalize, using the following methods: R.string. Name, @string/name you named yourself.
<resources> <!--properties Name= "name named"--<string name= "App_name" >Android4.0</string> <s Tring_array name= "Ball" > <item name= "basketball" > Basketball </item> <item name= "soccer" > Soccer </i Tem></resources>
Examples of Use:
Method used in the Xxx.java file: GetResource (). getString (R.string.app_name);
How to use the Xxx.xml file: android:text= "@string/app_name"
ii>array.xml file, define the contents of some arrays, using the same method as above.
<resources> <array name= "Color" > <item> #000 </item> <item> #fff </item> </array></resources>
Examples of Use:
Method used in the Xxx.java file: GetResource (). Getstringarray (R.arry.color);
Methods used in the Xxx.xml file: android:entries= "@array/color" (Note: Adding an array initial value for spinner)
iii>colors.xml file, mainly store some custom colors, using the same method as above.
<resources> <color name= "RED" > #f00 </color></resources>
Examples of Use:
Method used in the Xxx.java file: GetResource (). GetColor (r.color.red);
How to use the Xxx.xml file: android:background= "@color/red"
iv>dimens.xml file, mainly defines some dimensions, using the same method as above.
<resources> <dimen name= "Horizontal_margin" >15dp</dimen></resources>
Examples of Use:
How to use the Xxx.xml file: android:background= "@dimens/horizontal_margin"
Unit of size:
Symbol |
Name |
Usage |
Dp |
Independent pixels |
Regardless of device size |
Dx |
Pixel |
Regardless of device size |
Sp |
Enlarge pixel |
Typically used to set the size of text |
Length conversion: 1 pt = 1/72 in
Length Unit:
Symbol |
Name |
Pt |
Pounds |
Inch |
Inches |
Mm |
Mm |
Cm |
Cm |
v>bools.xml file, define a Boolean file, using the same method as above.
<resources> <bool name= "flag_on" >true</bool></resources>
vi>styles.xml files, placement style files, can make their own defined styles, also can hold the style of the system, styles can be applied in Windows, controls, layouts, theme settings, but must be consistent with the properties of the control (View). There are two types of defining styles:
Format one:
<style name= "Defines the name of the current style/theme (primarily for reference)" >
<item name= "Property name" > property value </item>
</style>
<style name= "MyStyle" > <item name= "android:layout_width" >match_parent</item> <itme name= " Android:textsize ">30sp</item></style>
Examples of Use:
How to use the Xxx.xml file: android:style= "@style/mystyle"
Use in the manifest file:
<application
Theme= "@style/mystyle"
...>
...
</application>
...
Format two:
<style name= "Defines the name of the current style/theme (primarily for reference)" parent= "Parent style name" >
<item name= "Property name" > property value </item>
</style>
<style name= "Mystylew2" parent= "MyStyle" > <item name= "Android:textcolor" > #0f0 </ITEM></STYLE&G T;<style name= "Mystyle.mystyle2" > </item name= "Android:textcolor" > #0f0 </item></style>
Examples of Use:
How to use the Xxx.xml file: android:style= "@style/mystyle"
Use in the manifest file:
<application
Theme= "@style/mystyle"
...>
...
</application>
...
Summary: The above is the settings of commonly used file properties under the Values folder, and other properties, usually at the time of assigning the value of the property directly to the assignment, reduce consumption, improve efficiency. The commonly used properties are assigned by calling names, facilitating the maintenance of the code, simplifying the code, and avoiding the "repeating wheel" phenomenon. These are the properties that you name and set, in fact, the Android system itself provides some properties for developers, such as: @android: Color/darker_gray calls the system to provide a dark gray. This acquisition method only obtains the system to provide the color, the style obtains also may use this method formula, as for the detailed explanation, later continues to add. Hope that everyone's study and development can be useful, the shortcomings of the Please do not enlighten us, thank you .
This article is from the "in the Eyes of the Sun" blog, please be sure to keep this source http://wang963825.blog.51cto.com/8695943/1864920
Android common resource files in--values folder files