- Syntaxe :
<property android:name="string" android:resource="resource specification" android:value="string" />
- Contenu dans :
<activity>
<activity-alias>
<application>
<provider>
<receiver>
<service>
- Description :
- Paire nom-valeur d'un élément de données arbitraires supplémentaires pouvant être fournies au composant parent. Un élément de composant peut contenir un nombre illimité de sous-éléments
<property>
. Les noms valides incluent toutes les constantes de propriété définies dans la classePackageManager
, les balisesPackageManager.Property
définies dans les classes telles queWindowProperties
ainsi que les constantes arbitraires définies ad hoc. Obtenez les valeurs individuellement à l'aide de la méthodePackageManager.getProperty()
.Spécifiez les valeurs ordinaires avec l'attribut
android:value
. Spécifiez les ID de ressource avec l'attributandroid:resource
. Les valeursandroid:value
etandroid:resource
ne sont pas valides.Par exemple, le code suivant attribue la valeur stockée dans la ressource
@string/kangaroo
au nomzoo
:<property android:name="zoo" android:value=”@string/kangaroo” />
En revanche, le code présenté ici attribue l'ID numérique de la ressource (et non la valeur stockée dans celle-ci) à
zoo
:<property android:name="zoo" android:resource=”@string/kangaroo” />
- Attributs :
android:name
- Nom de la propriété. Une erreur d'analyse se produit si plusieurs balises sœurs
<property>
portent le même nom. android:resource
- Référence à une ressource. L'ID de la ressource correspond à la valeur attribuée à la propriété. L'ID peut être récupéré à partir de la propriété par
PackageManager.Property.getResourceId()
. android:value
- Valeur attribuée à la propriété. Le tableau suivant indique les types de données et les méthodes d'accesseur valides pour l'attribut de valeur :
Type Accesseur PackageManager.Property Chaîne : utilisez des barres obliques inverses (\\) comme caractères d'échappement, par exemple \\n
et\\uxxxxx
pour un caractère UnicodegetString()
Entier : 100
, par exemplegetInteger()
Booléen : true
oufalse
getBoolean()
Couleur : format #rgb
,#argb
,#rrggbb
ou#aarrggbb
getInteger()
Flottant : 1.23
, par exemplegetFloat()
Remarque : Une balise
<property>
ne doit pas contenir à la fois les attributsandroid:value
etandroid:resource
. Dans ce cas, il est préférable d'utiliserandroid:resource
.- Première apparition :
- Niveau d'API 31
<propriété>
Le contenu et les exemples de code de cette page sont soumis aux licences décrites dans la Licence de contenu. Java et OpenJDK sont des marques ou des marques déposées d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/27 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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"]]