是否有可能在AndroidManifest.xml中标记的自定义属性?有可能、自定义、标记、属性

2023-09-04 08:39:31 作者:想要住進你心裡

我想自定义属性添加到我的Andr​​oidManifest.xml文件的应用程序标签。在Android环境中这可能吗?

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

推荐答案

是的。下面是一个例子。自定义标记是 ContentVersion

Yes. Here's an example. The custom tag is 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">

要访问它:

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