Syntax (syntax ):
<Meta-dataandroid: Name ="String"
Android: Resource ="Resource
Specification"
Android: value ="String"/>
Included in (contained in ):
<Activity>
<Activity-alias>
<Service>
<Cycler>
Description ):
This element uses the name-Value Pair format to provide any optional data to its parent component. A component element can contain any number of <meta-data> sub-elements. All the values defined in these elements are collected into a bundle object and provided to the packageiteminfo of the component. metadata attribute field.
The value is usually specified through its value attribute. However, you can also use the resource attribute to associate a resource ID with a value.
For example, the following code associates the value stored in the @ string/kangaroo resource with the "Zoo" Name:
<Meta-data
Android: Name = "Zoo"
Android: value = "@ string/Kangaroo"
/>
In addition, the resource attribute is used to allocate a digital resource ID to zoo, instead of the value stored in the resource. For example:
<Meta-data
Android: Name = "Zoo"
Android: Resource = "@ string/Kangaroo"
/>
Avoid using multiple independent <meta-data> entities to provide relevant data. On the contrary, if complex data needs to be associated with components, the data is saved as resources, and the resource attribute is used to notify related resource IDs to components.
Attributes (attributes ):
Android: Name
A unique name for the project. The naming rules of Java styles can ensure the uniqueness of names, for example:
Com. example. Project. activity. Fred.
Android: Resource
This attribute defines a resource to be referenced. The resource ID will be associated with this project. The bundle. getint () method can be used to obtain this ID from the bundle object of meta-data.
Android: Value
This property will assign a value to the project. The following table lists the data types that may be allocated and how to obtain the data:
Type |
Bundle object Method |
String. For a Unicode character, the double slash (\) is used for escape, such as \ n and \ uxxxx. |
Getstring () |
Integer, such as 100 |
Getint () |
Boolean value, true or false |
Getboolean () |
Color values, such as # RGB, # argb, # rrggbb, and # aarrggbb |
Getstring () |
Floating point value, such as 1.23 |
Getfloat () |
Introduced version (introduced in ):
API Level 1