Android manages application resources

Source: Internet
Author: User

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.

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.