假设我在以下位置声明了以下自定义主题themes.xml
:
<style name="Theme.Custom.Light" parent="@style/Theme.Sherlock.Light">
<item name="android:actionBarTabStyle">@style/Widget.Custom.Light.ActionBar.TabView</item>
<item name="android:actionBarTabTextStyle">@style/Widget.Custom.Light.ActionBar.TabText</item>
<item name="android:actionMenuTextColor">@color/ab_item_text</item>
<item name="android:actionMenuTextAppearance">@style/TextAppearance.Custom.Light.Widget.ActionBar.Menu</item>
</style>
从应用程序上下文中,我们可以得到Theme
当前应用的类使用
Theme myTheme = appContext.getTheme();
而且,我们还可以使用以下方法获取主题的资源 id:
int themeResId = appContext.getApplicationInfo().theme;
我想要的是
从我的代码中,我想检查以编程方式这是我正在使用的主题的父主题,以便区分Sherlock
, Sherlock.Light
& Sherlock.Light.DarkActionBar
.
在上面的示例中,我想知道我正在使用 Sherlock 主题的 Light 变体。
Note: 您可能想知道如果我在 xml 中声明了父级,为什么还需要检查它。原因是我处于一种我实际上不知道的特定情况,但这超出了这个问题的范围。
Theme myTheme = appContext.getTheme();
您可以使用它的父类
Theme myThemeParent = appContext.getTheme().getClass().getSuperclass();
并将其与Sherlock.getclass() 验证它是否是父级。其他比较也是如此。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)