我有一个平板电脑应用程序,我正在对其进行品牌 reshape ,因此根据用户类型有多个主题。
我想找到当前正在应用的主题的名称,然后基于该主题我可以做一些后端功能更改。
我必须动态设置一些图像资源,只要我传入正确的主题资源(R.style.redtheme)就可以了,但我想动态设置它。
TypedArray a = getTheme().obtainStyledAttributes(R.style.redtheme, new int[] {aTabResource.mDrawableAttrId});
为了进行样式设置,我创建了自定义属性,然后在样式中覆盖了它们。
如果没有简单的方法获取主题,我就保存一个偏好。
最佳答案
包管理器可以访问相当多的元数据。
可以这样访问:
int theme = 0; //0==not set
try
{
String packageName = getClass().getPackage().getName();
PackageInfo packageInfo = getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA);
theme = packageInfo.applicationInfo.theme;
}
catch (Exception e)
{
e.printStackTrace();
}
运行后,主题将具有样式资源。
关于android - 在 Android 应用程序中动态查找主题名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9535695/