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]