Read Catalogue
- Introducing the contents of the R file
- Describes referencing resources through R files
I. Contents of the R file
The R file in Android Studio is located in package name, R, Source, build-
Some points to note:
- The nature of the R file is a Java file with the file R.java
- The file is actually a public final class r{} class that contains all the inner classes that begin with public static final, in which all properties that begin with public static final int
- Open the R.java file in Android Studio and press Ctrl + Shift + minus key to see the overall contents of R.java
The contents of the R file (part of the code is omitted below):
Public final class r{//are all internal classes that begin 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 contents of the Inner class ID (part of the code is omitted below):
public static final class id{//are all properties that begin with public static final int ... public static final int button_1= "0x7f070022";p Ublic St atic final int button_2= "0x7f070023";p ublic static final int button_3= "0x7f070024"; ...}
[Back to top]
Ii. referencing resources through R files
Referencing resources in an XML file
- @[package:]type/name, in which the package name is used, and if it is referenced within the same package, the package name is not required, for example: @style/apptheme
- @android: Type/name, where Android represents an internal resource referencing the Android system
Referencing resources in a Java file
- R.type.name, for example: R.layout.first_layout, r.id.button_1
- Android. R.type.name, where Android represents an internal resource referencing the Android system
can see:
When referencing a resource in a Java file, a call is made directly to the contents of the R.java file, for example: R.id.button_1, which represents the button_1 attribute in the inner class that calls the ID under the class R.
The @ symbol in the XML file represents the resources in the call to the R.java file, for example: the @ symbol in the @style/apptheme can be understood as the R class, and the style represents the style inner class in the R class, Apptheme represents the Apptheme Property
[Back to top]
Android Note R file