你怎么到Android清单文件中添加用户定义的属性/值? [英] How do you add user defined properties/values in to the Android manifest file?

查看:191
本文介绍了你怎么到Android清单文件中添加用户定义的属性/值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加自定义属性/属性到清单文件,并能够在运行时读取它。我想这样做,这样我就可以通过这些表现属性自定义应用程序的行为。如何才能做到这一点?

I want to add a custom attribute / property into the manifest file, and be able to read it at run time. I want to do this so I can customize the app's behavior via these manifest properties. How can this be done?

推荐答案

可以的元数据添加到您的的Andr​​oidManifest.xml 文件,然后读取您的应用程序。

You can add meta-data to your AndroidManifest.xml file and then read that in your application.

将数据写入像这样:

<meta-data android:value="bar" android:name="foo"></meta-data>

和读取数据,像这样:

ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
Object value = (Object)ai.metaData.get("foo");

请参阅<一href="http://developer.android.com/guide/topics/manifest/meta-data-element.html">http://developer.android.com/guide/topics/manifest/meta-data-element.html

这篇关于你怎么到Android清单文件中添加用户定义的属性/值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆