Functions of several values files in the android Project

Source: Internet
Author: User

   

Recently, I decomcompiled several Android software and found some resource files that were not used before:
IDs. xml -- provides a unique resource ID for application-related resources. ID is a parameter required to obtain objects in XML, that is, id_name in object = findviewbyid (R. Id. id_name. These values can be referenced by Android. R. ID in the code.
If IDs are defined in IDs. XML, @ ID/price_edit can be defined as follows in layout; otherwise, @ + ID/price_edit can be defined.

Why do I use IDs?
I personally think it has the following functions:
(1) optimizing compilation efficiency.
We know that android components must use an int type ID attribute to identify their uniqueness. The ID attribute must start with @, for example, @ ID/ABC, @ + ID/xyz, etc.
If you use the form of "@ + ID/Name", if the name variable exists in R. Java, the component uses the value of the variable as the identifier. If the variable does not exist, add a new variable and assign the corresponding value to the variable (no duplicates ).
After a layout file is modified and saved, the system automatically generates the corresponding int type variable in the R. Java file. The variable name is the value after "/". For example, @ + ID/XYZ will generate intxyz = value in the R. Java file, where value is a hexadecimal number. If XYZ already has a variable with the same name in R. Java, the new variable is not generated, and the component uses the value of this existing variable.

In the form of @ ID/name, the pre-defined ID has been generated. When the configuration file is modified, the system will not be regenerated.

(2) unified resource ID management.

Public. xml -- describes a 32 id value specified by ATTR, ID, and drawable. This value is used in the current. xml file.

After we modify public. XML, execute the makeupdate-API command to add the changes to current. xml.

The definition of resource data in public. xml affects the current. xml file, which are in frameworks/asecoreesesvalues and framework/aseapicurrent. xml respectively.

When modifying the Kernel File, pay special attention to the synchronization of the public. xml file, which defines the binary compatibility of the resource file. Therefore, you need to be careful with this file, otherwise it may damage the backward compatibility of this version.

To avoid incompatibility, add new resources to the end of the same type of resources (the main id value increases progressively according to the ID value ). If it is placed in the middle, the subsequent similar resources will be assigned a new ID value, thus compromising compatibility.

Add ID:

1) Add a public ID item to IDs. XML, and add the corresponding ID item to public. xml. This method is not compatible with other versions.

2) Add a public ID entry to IDs. XML, and add a line before each entry. <! -@ Hide-> annotation, so you do not need to add corresponding items in public. xml. The form in the source code, so there will be no corresponding segments in current.

3) in the Self-written XML, the Android: Id = "@ + ID/id_name" format is used, just like in eclipse, after searching, you will find that android source code is also used in this way, IDs. XML and public. you don't need to modify the XML, so I'm not sure about compatibility.

Other commonly used resource files:

Attrs. XML-defines the class attributes to be referenced in the XML file. In other words, it specifies the values of the variables (that is, the actual roles of the attributes) in the class. These attributes are used in the class constructor. After reading one or two source codes, you will understand that the typedarray In the constructor is actually an attribute array. The members of the array will be assigned to the class members to complete the initialization from XML. Class constructor generally has three, one is class (context), this is used to create a class in the code, so it only contains one context; Class (context, attrs) and class (context,
Attrs, defstyle) is used to create classes from XML.

Styles. XML is the "style" of each control. styles are composed of attributes. When editing an XML file, the attributes set by different classes have the same and different attributes, which are controlled by styles. For details, see the contents of styles. xml.
Themes. XML is actually a style, but it is applicable to a wider range. I have not studied themes. XML based on others' opinions on the Internet.

Colors. xml -- defines various color values.

Strings. xml -- it defines the string constants used.

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.