Android 官方文檔:(二)應用清單 —— 2.13 <meta-data>標籤

來源:互聯網
上載者:User

syntax:
<meta-data android:name="string"           android:resource="resource specification"           android:value="string" />
contained in:
<activity>
<activity-alias>
<application>
<provider>
<receiver>

<service>
description:
A name-value pair for an item of additional, arbitrary data that can be supplied to the parent component. A component element can contain any number of <meta-data> sub elements. The values from all of them are collected in a single Bundle object and made available to the component as the PackageItemInfo.metaData field.

Ordinary values are specified through the value attribute. However, to assign a resource ID as the value, use the resource attribute instead. For example, the following code assigns whatever value is stored in the @string/kangaroo resource to the "zoo" name:

<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:

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

It is highly recommended that you avoid supplying related data as multiple separate <meta-data> 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.

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".
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.
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:
Type Bundle method
String value, using double backslashes (\\) to escape characters — such as "\\n" and "\\uxxxxx" for a Unicode character. getString()
Integer value, such as "100" getInt()
Boolean value, either "true" or "false" getBoolean()
Color value, in the form "#rgb", "#argb", "#rrggbb", or "#aarrggbb" getInt()
Float value, such as "1.23" getFloat()
introduced in:
API Level 1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.