【翻译】(55)meta-data元素

【翻译】(55)meta-data元素

 

see

http://developer.android.com/guide/topics/manifest/meta-data-element.html

 

原文见

http://developer.android.com/guide/topics/manifest/meta-data-element.html

 

-------------------------------

 

<meta-data>

 

meta-data元素

 

-------------------------------

 

* syntax:

 

* 语法:

 

-------------------------------

 

<meta-data android:name="string"

           android:resource="resource specification"

           android:value="string" />

 

-------------------------------

 

* contained in:

 

* 被包含在:

 

<activity> 

<activity-alias> 

<service> 

<receiver>

 

* 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.

 

一个用于附加的、任意的数据条目的名称-值对,它可以被提供给父组件。一个组件元素可以包含任意数量的<meta-data>子元素。来自它们全体中的值被收集进一个单一的Bundle对象并且让它对组件可用作为PackageItemInfo.metaData的域。

 

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:

 

普通的值通过value属性被指定。然而,为了赋予一个资源ID作为值,请使用resource属性代替。例如,以下代码赋予存储在@string/kangaroo资源中的任意值给"zoo"名称:(注:kangaroo的意思是袋鼠)

 

-------------------------------

 

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

 

另一方面,使用resource属性将赋予"zoo"该资源的数值ID,而非存储在资源中的值。

 

-------------------------------

 

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

 

强烈建议你避免提供相关的数据作为多个单独的<meta-data>条目。取而代之,如果你用复杂的数据要与一个组件关联,存储它作为一个资源并使用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".

 

条目的唯一名称。为了确保名称是唯一的,使用一个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是赋给该条目的值。ID可以通过Bundle.getInt()方法从元数据Bundle中取出。

 

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

 

赋予给条目的值,可以赋予作为值的数据类型以及组件用来取出那些值的Bundle方法被列举在以下表格中:

 

-------------------------------

 

* Type Bundle method

 

* 类型 Bundle方法

 

* String value, using double backslashes (\\) to escape characters — such as "\\n" and "\\uxxxxx" for a Unicode character. getString()

 

* 字符串值,使用双反斜杠(\\)转义字符——诸如"\\n"和用于一个Unicode字符的"\\uxxxxx"。 getString()

 

* Integer value, such as "100" getInt()

 

* 整型值,诸如"100" getInt()

 

* Boolean value, either "true" or "false" getBoolean()

 

* 布尔型,"true"或"false" getBoolean()

 

* Color value, in the form "#rgb", "#argb", "#rrggbb", or "#aarrggbb" getString()

 

* 颜色值,格式为"#rgb","#argb","#rrggbb",或"#aarrggbb" getString()

 

* Float value, such as "1.23" getFloat()

 

* 浮点型,诸如"1.23" getFloat()

 

-------------------------------

 

* introduced in:

 

* 引入:

 

API Level 1

 

API级别1

 

Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.

 

除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。

 

Android 4.0 r1 - 10 Feb 2012 0:44

 

-------------------------------

 

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

 

(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)

 

(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:

* ソフトウェア技術ドキュメントを勝手に翻訳

http://www.techdoctranslator.com/android

* Ley's Blog

http://leybreeze.com/blog/

* 农民伯伯

http://www.cnblogs.com/over140/

* Android中文翻译组

http://androidbox.sinaapp.com/


你可能感兴趣的:(meta)