【问题标题】:Android ActionBar: how to get its theme?Android ActionBar:如何获取它的主题?
【发布时间】:2014-01-29 02:44:17
【问题描述】:

我知道 ActionBar 有很多内置主题:Holo Light、Holo Dark、Holo Light with Dark ActionBar...

有没有办法知道,ActionBar当前的主题是Dark还是Light?

【问题讨论】:

标签: android android-actionbar actionbarsherlock android-theme


【解决方案1】:

在 Android 开发者社区 (Google+) 的建议下,我终于从 HoloEverywhere 源代码中找到了这样的方法:ThemeManager.getThemeType(context)

public static int getThemeType(Context context) {
        TypedArray a = context.obtainStyledAttributes(new int[] {
                R.attr.holoTheme
        });
        final int holoTheme = a.getInt(0, 0);
        a.recycle();
        switch (holoTheme) {
            case 1:
                return DARK;
            case 2:
                return LIGHT;
            case 3:
                return MIXED;
            case 4:
                return PreferenceManagerHelper.obtainThemeTag();
            case 0:
            default:
                return INVALID;
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-18
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-30
    • 2016-03-08
    • 1970-01-01
    相关资源
    最近更新 更多