从主题ID Android的主题名称 [英] Android theme name from theme ID
本文介绍了从主题ID Android的主题名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道当前主题的名称,我已经有主题的资源ID。任何人都知道如何获得当前的主题的名称
感谢
解决方案
公共字符串getThemeName()
{
PackageInfo packageInfo;
尝试
{
packageInfo = getPackageManager()getPackageInfo(getPackageName(),PackageManager.GET_META_DATA)。
INT themeResId = packageInfo.applicationInfo.theme;
返回getResources()getResourceEntryName(themeResId)。
}
赶上(的NameNotFoundException E)
{
返回null;
}
}
解决方案
尝试使用 getResourceEntryName()
或 getResourceName()
在资源
,这取决于你的目标是什么。
I need to know the name of the current theme, I already have the theme's resource ID. Anybody knows how to get the current theme's name?
Thanks
Solution
public String getThemeName()
{
PackageInfo packageInfo;
try
{
packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
int themeResId = packageInfo.applicationInfo.theme;
return getResources().getResourceEntryName(themeResId);
}
catch (NameNotFoundException e)
{
return null;
}
}
解决方案
Try using getResourceEntryName()
or getResourceName()
on Resources
(typically retrieved via getResources()
), depending on what you are aiming for.
这篇关于从主题ID Android的主题名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文