- ไวยากรณ์:
<property android:name="string" android:resource="resource specification" android:value="string" />
- ที่อยู่ใน:
<activity>
<activity-alias>
<application>
<provider>
<receiver>
<service>
- description:
- คู่ชื่อ-ค่าสำหรับรายการข้อมูลเพิ่มเติมที่กำหนดเองซึ่งระบุไปยังฟังก์ชัน
คอมโพเนนต์หลัก องค์ประกอบคอมโพเนนต์จะมีองค์ประกอบย่อย
<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” />
อย่างไรก็ตาม โค้ดตรงนี้จะกำหนดรหัสตัวเลขของทรัพยากร ไม่ใช่ค่าที่จัดเก็บไว้ในทรัพยากร
zoo
:<property android:name="zoo" android:resource=”@string/kangaroo” />
- ดังนี้
android:name
- ชื่อที่พัก ข้อผิดพลาดในการแยกวิเคราะห์จะเกิดขึ้นเมื่อแท็ก
<property>
หลายรายการซึ่งอยู่ติดกันมี ชื่อเดียวกัน android:resource
- การอ้างอิงแหล่งข้อมูล รหัสของทรัพยากรคือค่าที่กำหนดให้พร็อพเพอร์ตี้ ดึงรหัสได้
จากพร็อพเพอร์ตี้โดย
PackageManager.Property.getResourceId()
android:value
- ค่าที่กําหนดให้กับพร็อพเพอร์ตี้ ตารางต่อไปนี้แสดงรายการประเภทข้อมูลและวิธีเข้าถึงที่ถูกต้องสำหรับค่า
แอตทริบิวต์:
ประเภท ตัวเข้าถึง PackageManager.Property สตริง: ใช้เครื่องหมายแบ็กสแลชคู่ (\\) เพื่อหลีกอักขระ เช่น \\n
และ\\uxxxxx
สำหรับอักขระ UnicodegetString()
จำนวนเต็ม: เช่น 100
getInteger()
บูลีน: true
หรือfalse
ก็ได้getBoolean()
สี: ในรูปแบบ #rgb
,#argb
,#rrggbb
หรือ#aarrggbb
getInteger()
ลอย: เช่น 1.23
getFloat()
หมายเหตุ: แท็ก
<property>
ไม่ควรมีทั้งandroid:value
และandroid:resource
หากเป็นเช่นนั้น แนะนำให้ใช้android:resource
- เปิดตัวใน
- API ระดับ 31
<property>
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],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"]]