- תחביר:
<meta-data android:name="string" android:resource="resource specification" android:value="string" />
- בתוך:
<activity>
<activity-alias>
<application>
<provider>
<receiver>
<service>
- תיאור:
- צמד של שם-ערך לפריט של נתונים שרירותיים נוספים שיכולים להיות
סופק לרכיב ההורה. רכיב רכיב יכול להכיל כל
מספר
<meta-data>
אלמנטים משניים. הערכים מכל הם נאספים באובייקטBundle
יחיד, זמינים לרכיב בתור שדהPackageItemInfo.metaData
.מציינים ערכים רגילים באמצעות הפונקציה
value
. כדי להקצות מזהה משאב בתור הערך, משתמשים במקום זאת, צריך להוסיף את המאפייןresource
. לדוגמה, הקוד הבא מקצה ערך כלשהו שמאוחסן ב-@string/kangaroo
משאב לשםzoo
:<meta-data android:name="zoo" android:value="@string/kangaroo" />
לעומת זאת, שימוש במאפיין
resource
מקצה אתzoo
המזהה המספרי של המשאב, לא הערך שמאוחסן במשאב:<meta-data android:name="zoo" android:resource="@string/kangaroo" />
מומלץ מאוד להימנע מאספקת נתונים קשורים מספר רשומות נפרדות של
<meta-data>
. במקום זאת, אם אם יש נתונים מורכבים שאפשר לשייך לרכיב, לאחסן אותו כמשאב להשתמש במאפייןresource
כדי לציין את הרכיב של המזהה שלו. - :
android:name
- שם ייחודי לפריט. כדי שהשם יהיה ייחודי, השתמשו ב-
המוסכמה למתן שמות בסגנון Java, כמו
"
com.example.project.activity.fred
". android:resource
- הפניה למשאב. מזהה המשאב הוא הערך שהוקצה
לפריט. המזהה מאוחזר מהמטא-נתונים
Bundle
באמצעותBundle.getInt()
. android:value
- הערך שהוקצה לפריט. את סוגי הנתונים שניתן להקצות כערכים,
השיטות
Bundle
שבהן רכיבים משתמשים לאחזור הערכים האלה מפורטות בטבלה הבאה:
סוג שיטת החבילה מחרוזת: צריך להשתמש לוכסנים הפוכים כפולים ( \\
) כדי לסמן תווים בתו בריחה (escape), כמו\\n
לשורה חדשה ו-\\uxxxxx
לתו UnicodegetString()
מספר שלם: לדוגמה, 100
getInt()
ערך בוליאני: true
אוfalse
getBoolean()
צבע: בפורמט #rgb
,#argb
,#rrggbb
או#aarrggbb
getInt()
מספר ממשי (float): לדוגמה, 1.23
getFloat()
- הושקו ב:
- רמת API 1
<meta-data>
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. 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,["# <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"]]