How to use system resources for Android Development Tutorials Android resource file _android

Source: Internet
Author: User

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

Related Article

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.