Android selects the most appropriate value for a resource identifier based on the current hardware, device, and language configuration. 1. Use static class R to access resources in code. R classes are generated based on external resources and created during project compilation. Each subclass of R represents its related resources as variables, such as R. string. app_name. However, it is only an integer that represents the position of the resource in the resource table. You also need to use constructors or methods similar to setContentView to pass resource variables. When you need an instance of the resource itself, you need to use an auxiliary method to extract them from the resource table. The Resources class contains getter for each available resource type. It is usually used by passing the ID of the resource instance you need. For example:
<Span style = "white-space: pre"> </span> Resources myResource = getResources (); <span style = "white-space: pre "> </span> String [] stringarray = myResource. getStringArray (R. array. string_array );
2. Referencing resources within a resource is very suitable for layout and style. Reference a resource and use it as the property value of other XML resources. With the @ symbol, You can reference another resource in one resource.
<Span style = "white-space: pre"> </span> attribute = "@ [packagename:] resourcetype/resourceidentifier ";
3. Use system resources to use system resources in code using the android. R class. To access system resources in XML, you must specify android as the package name, for example, android: text = "@ android: string/httpErrorBadUrl ";