- Syntaxe :
<meta-data 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
<meta-data>
. Les valeurs de chacun d'eux sont collectées dans un seul objetBundle
et mises à la disposition du composant en tant que champPackageItemInfo.metaData
.Spécifiez les valeurs ordinaires via le
value
. . Pour attribuer un ID de ressource en tant que valeur, utilisez la méthoderesource
. Par exemple : le code suivant attribue la valeur stockée dans@string/kangaroo
la ressource au nomzoo
:<meta-data android:name="zoo" android:value="@string/kangaroo" />
En revanche, l'attribut
resource
attribuezoo
l'ID numérique de la ressource, et non la valeur stockée dans la ressource:<meta-data android:name="zoo" android:resource="@string/kangaroo" />
Nous vous recommandons vivement de ne pas fournir de données associées plusieurs entrées
<meta-data>
distinctes. À la place, si vous avez des données complexes à associer à un composant, stockez-les en tant que ressource et utilisez l'attributresource
pour informer le composant de son ID. - Attributs :
android:name
- Nom unique de l'élément. Pour que le nom reste unique, utilisez un
Convention d'attribution de noms de style Java, par exemple
"
com.example.project.activity.fred
". android:resource
- Référence à une ressource. L'ID de la ressource correspond à la valeur attribuée à l'élément. L'ID est extrait des métadonnées
Bundle
à l'aide de la méthodeBundle.getInt()
. android:value
- Valeur attribuée à l'élément. Les types de données pouvant être attribués en tant que valeurs et
Les méthodes
Bundle
que les composants utilisent pour récupérer ces valeurs sont répertoriées dans le tableau suivant:
Type Méthode du bundle Chaîne: utilisez des doubles barres obliques inverses ( \\
) pour échapper les caractères, tels que\\n
pour une nouvelle ligne et\\uxxxxx
pour un caractère UnicodegetString()
Entier: 100
, par exemplegetInt()
Booléen: true
oufalse
getBoolean()
Couleur: format #rgb
,#argb
,#rrggbb
ou#aarrggbb
getInt()
Flottant: par exemple, 1.23
getFloat()
- Première apparition :
- Niveau d'API 1
<métadonnées-données>
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,["# <meta-data\u003e\n\nsyntax:\n:\n\n ```xml\n \u003cmeta-data 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\n supplied to the parent component. A component element can contain any\n number of `\u003cmeta-data\u003e` subelements. The values from all of\n them are collected in a single [Bundle](/reference/android/os/Bundle) object and made\n available to the component as the\n [PackageItemInfo.metaData](/reference/android/content/pm/PackageItemInfo#metaData) field.\n\n Specify ordinary values through the [value](/guide/topics/manifest/meta-data-element#val)\n attribute. To assign a resource ID as the value, use the\n [resource](/guide/topics/manifest/meta-data-element#rsrc) attribute instead. For example,\n the following code assigns whatever value is stored in the `@string/kangaroo`\n resource to the `zoo` name:\n\n\n ```xml\n \u003cmeta-data android:name=\"zoo\" android:value=\"@string/kangaroo\" /\u003e\n ```\n\n\n On the other hand, using the `resource` attribute assigns `zoo`\n the numeric ID of the resource, not the value stored in the resource:\n\n\n ```xml\n \u003cmeta-data android:name=\"zoo\" android:resource=\"@string/kangaroo\" /\u003e\n ```\n\n\n We highly recommend that you avoid supplying related data as\n multiple separate `\u003cmeta-data\u003e` entries. Instead, if you\n have complex data to associate with a component, store it as a resource and\n use the `resource` attribute to inform the component of its ID.\n\nattributes:\n:\n\n `android:name`\n : A unique name for the item. To keep the name unique, use a\n Java-style naming convention, such as\n \"`com.example.project.activity.fred`\".\n\n `android:resource`\n : A reference to a resource. The ID of the resource is the value assigned\n to the item. The ID is retrieved from the meta-data `Bundle` using the\n [Bundle.getInt()](/reference/android/os/BaseBundle#getInt(java.lang.String)) method.\n\n `android:value`\n : The value assigned to the item. The data types that can be assigned as values and the\n `Bundle` methods that components use to retrieve those values are listed in the following table:\n\n\n | Type | Bundle method |\n |---------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|\n | String: use double backslashes (`\\\\`) to escape characters, such as `\\\\n` for a new line and `\\\\uxxxxx` for a Unicode character | [getString()](/reference/android/os/BaseBundle#getString(java.lang.String)) |\n | Integer: for example, `100` | [getInt()](/reference/android/os/BaseBundle#getInt(java.lang.String)) |\n | Boolean: either `true` or `false` | [getBoolean()](/reference/android/os/BaseBundle#getBoolean(java.lang.String)) |\n | Color: in the form `#rgb`, `#argb`, `#rrggbb`, or `#aarrggbb` | [getInt()](/reference/android/os/BaseBundle#getInt(java.lang.String)) |\n | Float: for example, `1.23` | [getFloat()](/reference/android/os/Bundle#getFloat(java.lang.String)) |\n\n\nintroduced in:\n: API level 1"]]