- 语法:
<property android:name="string" android:resource="resource specification" android:value="string" />
- 包含于:
<activity>
<activity-alias>
<application>
<provider>
<receiver>
<service>
- 说明:
- 可以向父组件提供的其他任意数据项的名称值对。一个组件元素可以包含任意数量的
<property>
子元素。有效名称包括PackageManager
类中定义的任何属性常量,WindowProperties
等类中定义的PackageManager.Property
标记以及任意临时定义的常量。使用PackageManager.getProperty()
方法单独获取值。使用
android:value
属性指定普通值。使用android:resource
属性指定资源 ID。同时指定android:value
和android:resource
是无效的。例如,以下代码会将
@string/kangaroo
资源中存储的任何值分配给zoo
名称:<property android:name="zoo" android:value=”@string/kangaroo” />
但是,此处的代码会将资源的数字 ID(而不是存储在资源中的值)分配给
zoo
:<property android:name="zoo" android:resource=”@string/kangaroo” />
- 属性:
android:name
- 属性的名称。如果多个同级
<property>
标记具有相同的名称,则会导致解析错误。 android:resource
- 对资源的引用。资源的 ID 是分配给该属性的值。可通过
PackageManager.Property.getResourceId()
从属性中检索该 ID。 android:value
- 为属性分配的值。下表列出了 value 属性的有效数据类型和访问器方法:
类型 PackageManager.Property 访问器 字符串:使用双反斜杠 (\\) 转义字符;例如使用 \\n
和\\uxxxxx
表示 Unicode 字符getString()
整数:例如 100
getInteger()
布尔值: true
或false
getBoolean()
颜色:采用 #rgb
、#argb
、#rrggbb
或#aarrggbb
格式getInteger()
浮点数:例如 1.23
getFloat()
注意:
<property>
标记不应同时包含android:value
和android:resource
属性,建议使用android:resource
。- 引入于:
- API 级别 31
<属性>
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# <property\u003e\n\nsyntax:\n:\n\n ```xml\n \u003cproperty android:name=\"string\"\n android:resource=\"resource specification\"\n android:value=\"string\" /\u003e\n ```\n\ncontained in:\n: [\u003cactivity\u003e](/guide/topics/manifest/activity-element)\n\n [\u003cactivity-alias\u003e](/guide/topics/manifest/activity-alias-element)\n\n [\u003capplication\u003e](/guide/topics/manifest/application-element)\n\n [\u003cprovider\u003e](/guide/topics/manifest/provider-element)\n\n [\u003creceiver\u003e](/guide/topics/manifest/receiver-element)\n\n [\u003cservice\u003e](/guide/topics/manifest/service-element)\n\ndescription:\n: A name-value pair for an item of additional, arbitrary data that can be supplied to the\n parent component. A component element can contain any number of `\u003cproperty\u003e` subelements. Valid names\n include any of the [property constants](/reference/android/content/pm/PackageManager#constants_1) defined in\n the [PackageManager](/reference/android/content/pm/PackageManager) class,\n [PackageManager.Property](/reference/android/content/pm/PackageManager.Property) tags defined\n in classes such as [WindowProperties](/reference/kotlin/androidx/window/WindowProperties), and arbitrary constants defined ad hoc. Obtain values individually using the\n [PackageManager.getProperty()](/reference/android/content/pm/PackageManager#getProperty(java.lang.String,%20java.lang.String)) method.\n\n Specify ordinary values with the [android:value](/guide/topics/manifest/property-element#val)`\n ` attribute. Specify resource IDs with the\n [android:resource](/guide/topics/manifest/property-element#rsrc) attribute. Specifying\n both `android:value` and `android:resource` is invalid.\n\n\n For example, the following code assigns whatever value is stored in the `@string/kangaroo` resource to\n the `zoo` name:\n\n\n ```xml\n \u003cproperty android:name=\"zoo\" android:value=”@string/kangaroo” /\u003e\n ```\n\n\n The code here, however, assigns the numeric ID of the resource, not the value stored in the resource, to\n `zoo`:\n\n\n ```xml\n \u003cproperty android:name=\"zoo\" android:resource=”@string/kangaroo” /\u003e\n ```\n\nattributes:\n:\n\n `android:name`\n : The name of the property. A parsing error results if multiple, sibling `\u003cproperty\u003e` tags have the\n same name.\n\n `android:resource`\n : A reference to a resource. The ID of the resource is the value assigned to the property. The ID can be retrieved\n from the property by\n [PackageManager.Property.getResourceId()](/reference/android/content/pm/PackageManager.Property#getResourceId()).\n\n `android:value`\n : A value assigned to the property. The following table lists valid data types and accessor methods for the value\n attribute: \n\n\n | Type | PackageManager.Property accessor |\n |-----------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|\n | String: Use double backslashes (\\\\\\\\) to escape characters; for example, `\\\\n` and `\\\\uxxxxx` for a Unicode character | [getString()](/reference/android/content/pm/PackageManager.Property#getString()) |\n | Integer: For example, `100` | [getInteger()](/reference/android/content/pm/PackageManager.Property#getInteger()) |\n | Boolean: Either `true` or `false` | [getBoolean()](/reference/android/content/pm/PackageManager.Property#getBoolean()) |\n | Color: In the form `#rgb`, `#argb`, `#rrggbb`, or `#aarrggbb` | [getInteger()](/reference/android/content/pm/PackageManager.Property#getInteger()) |\n | Float: For example, `1.23` | [getFloat()](/reference/android/content/pm/PackageManager.Property#getFloat()) |\n\n\nintroduced in:\n: API Level 31"]]