直接前往內容

最常造訪的網頁

最近瀏覽的網頁

navigation

<meta-data>

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> subelements. 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
本網站使用 Cookie 儲存你在此指定的語言和顯示選項偏好設定。

掌握有關 Android 開發人員的最新消息和實用訣竅,協助你製作最受歡迎的 Google Play 內容。

* 必填欄位

訂閱成功!

在 WeChat 上追蹤 Google Developers

你要以瀏覽這個網站嗎?

你要求以顯示這個網頁,但你為此網站指定的語言偏好設定為

是否要變更語言偏好設定並改用瀏覽網站?稍後如要變更語言偏好設定,請利用位在每個網頁最下方的語言選單來調整設定。

你的 API 層級必須達 以上才能存取這個級別

本說明文件已隱藏,因為你為該文件選取的 API 層級為 。使用左側導覽列上方的選取工具即可變更說明文件的 API 層級。

如需進一步瞭解如何為應用程式指定 API 層級的相關資訊,請參閱 Supporting Different Platform Versions (支援不同的平台版本) (英文)。

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)