Android note R file, android note File

Source: Internet
Author: User

Android note R file, android note File
Reading directory

  • Introduction to the content of the R File
  • Introduction to resource reference through R files

I. Content of the R File

In Android Studio, the R file is located in app-> build-> generated-> source-> r-> debug-> package name-> R

Notes:

  • The essence of the R file is a java file, which is R. java
  • This file is actually a public final class R {} class, which contains all internal classes starting with public static final. All these internal classes are attributes starting with public static final int.
  • Open the R. java file in Android Studio and press Ctrl + Shift + minus key to view the overall content of R. java.

The content of the R file (some code is omitted below ):

Public final class R {// all internal classes starting with publi static final... public static final class layout {...} public static final class id {...} public static final class drawable {...} public static final class mipmap {...} public static final class color {...} public static final class string {...} public static final class style {...}...}

The content in the internal class id (some code is omitted below ):

Public static final class id {// all attributes starting with public static final int... public static final int button_1 = "0x7f070022"; public static final int button_2 = "0x7f070023"; public static final int button_3 = "0x7f070024 ";...}

[Back to Top]


2. Use the R file to reference resources

Reference resources in xml files

  • @ [Package:] type/name. package indicates the package name. If it is referenced in the same package, you do not need to write the package name, for example, @ style/AppTheme.
  • @ Android: type/name. android indicates referencing internal resources of the android system.

Reference resources in java files

  • R. type. name, for example: R. layout. first_layout, R. id. button_1
  • Android. R. type. name. android indicates referencing the internal resources of the android system.

You can see:

When referencing resources in a java file. call the content in the java file, for example, R. id. button_1, indicating to call the button_1 attribute of the internal class id under the R class

In the xml file, @ indicates calling R. for example, the @ symbol in the @ style/AppTheme file can be understood as the R class, while the style indicates the internal class of the style in the R class, And the AppTheme indicates, appTheme attributes in the style internal class


[Back to Top]


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.