- 문법:
<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
속성을 통해 일반 값을 지정합니다. 리소스 ID를 값으로 할당하려면 대신resource
속성을 사용합니다. 예를 들어 다음 코드는@string/kangaroo
리소스에 저장된 값을zoo
이름에 할당합니다.<meta-data android:name="zoo" android:value="@string/kangaroo" />
하지만
resource
속성을 사용하면 리소스에 저장된 값이 아니라 리소스의 숫자 ID를zoo
에 할당합니다.<meta-data android:name="zoo" android:resource="@string/kangaroo" />
관련 데이터를 별도의 여러
<meta-data>
항목으로 제공하지 않는 것이 좋습니다. 대신 구성요소와 연결할 데이터가 복잡한 경우 데이터를 리소스로 저장한 다음resource
속성을 사용해 구성요소에 리소스 ID를 알립니다. - 속성
android:name
- 항목의 고유한 이름입니다. 이름을 고유하게 유지하려면 '
com.example.project.activity.fred
'와 같은 Java 스타일 이름 지정 규칙을 사용합니다. android:resource
- 리소스의 참조입니다. 리소스 ID는 항목에 할당된 값입니다. ID는
Bundle.getInt()
메서드를 사용하여Bundle
메타데이터에서 가져옵니다. android:value
- 항목에 할당된 값입니다. 다음 표에는 값으로 할당할 수 있는 데이터 유형 및 구성요소에서 이러한 값을 가져오는 데 사용하는
Bundle
메서드가 표시되어 있습니다.
유형 Bundle 메서드 문자열: 이중 백슬래시( \\
)를 사용하여 문자를 이스케이프 처리합니다(예: 줄바꿈의 경우\\n
, 유니코드 문자의 경우\\uxxxxx
).getString()
정수: 100
을 예로 들 수 있습니다.getInt()
불리언: true
또는false
입니다.getBoolean()
색상: #rgb
,#argb
,#rrggbb
또는#aarrggbb
형식입니다.getInt()
부동 소수점 수: 1.23
을 예로 들 수 있습니다.getFloat()
- 도입 수준:
- API 수준 1
<meta-data>
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 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"]]