- 語法:
<property android:name="string" android:resource="resource specification" android:value="string" />
- 包含於:
<activity>
<activity-alias>
<application>
<provider>
<receiver>
<service>
- 說明:
- 適用於其他任意資料項目的名稱/值配對,可提供到
父項元件。元件元素中可包含任意數量的
<property>
子元素。有效名稱 加入在PackageManager
類別 已定義PackageManager.Property
個標記 在WindowProperties
等類別中,另外也要臨時定義的任意常數。使用PackageManager.getProperty()
方法。請使用
android:value
屬性指定一般值。使用android:resource
屬性。指定android:value
和android:resource
無效。例如,以下程式碼會將
@string/kangaroo
資源中儲存的任何值指派給zoo
名稱:<property android:name="zoo" android:value=”@string/kangaroo” />
不過,這裡的程式碼會將資源的數字 ID,而非資源中儲存的值指派給該 ID 給
zoo
:<property android:name="zoo" android:resource=”@string/kangaroo” />
- 屬性:
android:name
- 屬性的名稱。如有多個同層
<property>
標記包含 這個名稱。 android:resource
- 資源參照。資源 ID 是指派給該屬性的值。可擷取 ID
使用
PackageManager.Property.getResourceId()
。 android: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 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間: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"]]