meta-data标签

meta-data API介绍:

参考资料 https://developer.android.com/guide/topics/manifest/meta-data-element.html#rsrc

the following code assigns whatever value is stored in the @string/kangaroo resource to the “zoo” name:
下面这段代码将存在@string/kangaroo资源的值,赋值给名称为“zoo”的属性。

<meta-data android:name="zoo" android:value="@string/kangaroo" />

On the other hand, using the resource attribute would assign “zoo” the numeric ID of the resource, not the value stored in the resource:
使用资源属性将会给“zoo”赋值资源ID,而不是这个ID存储的值。

<meta-data android:name="zoo" android:resource="@string/kangaroo" />

It is highly recommended that you avoid supplying related data as multiple separate entries. Instead, if you have complex data to associate with a component, store it as a resource and use the resource attribute to inform the component of its ID.
建议大家不要将相关的数据分成多个独立的条目添加到组件中去。加入你有复杂的数据绑定到某个组件中,将其存到resource中,然后使用resource属性表示该ID对应组件的属性。

ATTRIBUTES:

  • android:name

A unique name for the item. To ensure that the name is unique, use a Java-style naming convention — for example, “com.example.project.activity.fred”.
某个条目特有的名称,为确保name的唯一性,使用Java命名惯例-包名.类名,例如com.example.project.activity.fred。

  • android:resource

A reference to a resource. The ID of the resource is the value assigned to the item. The ID can be retrieved from the meta-data Bundle by the Bundle.getInt() method.
对于资源的引用,资源的ID就是赋值给item标签的值,这个ID可以通过meta-data的Bundle.getInt()方法得到。

  • android:value

The value assigned to the item. The data types that can be assigned as values and the Bundle methods that components use to retrieve those values are listed in the following table:

item标签上的value值,可以赋值给item的数据类型和组建个用来获取这些value值的Bundle方法均列在下表:

TablesAre
String value, using double backslashes (\\) to escape characters — such as “\\n” and “\\uxxxxx” for a Unicode character. 字符串。使用双反斜线表示转义字符,如”\n”。还有”\\uxxxxx”表示Unicode编码的字符。getString()
Integer value, such as “100”getInt()
Boolean value, either “true” or “falsegetBoolean()
Color value, in the form “#rgb”, “#argb”, “#rrggbb”, or “#aarrggbb”. 使用#rgb,#argb,#rrggbb,#aarrggbb表示颜色,a为透明度getInt()
Float value, such as “1.23”getFloat()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值