AndroidManifest.xml标签中是否可以有自定义属性?

时间:2022-11-26 13:40:15

I would like to add a custom attribute to the application tag of my AndroidManifest.xml file. Is this possible in the Android environment?

我想在我的AndroidManifest.xml文件的应用程序标记中添加自定义属性。这在Android环境中是否可行?

5 个解决方案

#1


61  

Yes. Here's an example. The custom tag is ContentVersion.

是。这是一个例子。自定义标记是ContentVersion。

<application android:name=".MyApplication"
             android:icon="@drawable/icon"
             android:label="@string/app_name">

    <meta-data android:name="ContentVersion" android:value="1.9" />

    <activity android:name="com.someone.something.MainActivity"
              android:theme="@android:style/Theme.Translucent.NoTitleBar"
              android:screenOrientation="sensor"
              android:label="@string/app_name">

To access it:

要访问它:

    ApplicationInfo ai = _context.getPackageManager().getApplicationInfo(_context.getPackageName(),PackageManager.GET_META_DATA);
    ai.metaData.get("ContentVersion")

#2


3  

You cannot define custom attribute to a predefined tag, but you can add key-value pairs called meta-data.

您无法为预定义标记定义自定义属性,但可以添加称为元数据的键值对。

#3


0  

You could go for a SharedPreferences, instead (aka, settings).

您可以选择使用SharedPreferences(也就是设置)。

#4


0  

In the tag (as well as service and receiver), you can use the tag (http://developer.android.com/guide/topics/manifest/meta-data-element.html )

在标签(以及服务和接收器)中,您可以使用标签(http://developer.android.com/guide/topics/manifest/meta-data-element.html)

It contains a name and a value or a resource ID.

它包含名称和值或资源ID。

You retrieve it through the PackageManager.

您可以通过PackageManager检索它。

#5


-2  

If anybody needs that for Xamarin (Mono for Android) I couldn't find the constant, but i found the value for it, which is 128.

如果有人需要Xamarin(Mono for Android),我找不到常数,但我找到了它的值,即128。

I used a "for" condition to go through all values from 0 to 1000 and check whenever the MetaData property was not null. lol

我使用“for”条件遍历0到1000之间的所有值,并检查MetaData属性何时不为null。大声笑

#1


61  

Yes. Here's an example. The custom tag is ContentVersion.

是。这是一个例子。自定义标记是ContentVersion。

<application android:name=".MyApplication"
             android:icon="@drawable/icon"
             android:label="@string/app_name">

    <meta-data android:name="ContentVersion" android:value="1.9" />

    <activity android:name="com.someone.something.MainActivity"
              android:theme="@android:style/Theme.Translucent.NoTitleBar"
              android:screenOrientation="sensor"
              android:label="@string/app_name">

To access it:

要访问它:

    ApplicationInfo ai = _context.getPackageManager().getApplicationInfo(_context.getPackageName(),PackageManager.GET_META_DATA);
    ai.metaData.get("ContentVersion")

#2


3  

You cannot define custom attribute to a predefined tag, but you can add key-value pairs called meta-data.

您无法为预定义标记定义自定义属性,但可以添加称为元数据的键值对。

#3


0  

You could go for a SharedPreferences, instead (aka, settings).

您可以选择使用SharedPreferences(也就是设置)。

#4


0  

In the tag (as well as service and receiver), you can use the tag (http://developer.android.com/guide/topics/manifest/meta-data-element.html )

在标签(以及服务和接收器)中,您可以使用标签(http://developer.android.com/guide/topics/manifest/meta-data-element.html)

It contains a name and a value or a resource ID.

它包含名称和值或资源ID。

You retrieve it through the PackageManager.

您可以通过PackageManager检索它。

#5


-2  

If anybody needs that for Xamarin (Mono for Android) I couldn't find the constant, but i found the value for it, which is 128.

如果有人需要Xamarin(Mono for Android),我找不到常数,但我找到了它的值,即128。

I used a "for" condition to go through all values from 0 to 1000 and check whenever the MetaData property was not null. lol

我使用“for”条件遍历0到1000之间的所有值,并检查MetaData属性何时不为null。大声笑