使用 xml 参考将错误的主题应用于 PreferenceActivity

Wrong Theme being applied to PreferenceActivity with xml reference

当我使用 XML 引用来引用所述主题时,我似乎无法在 PreferenceActivity 上实现主题。
我有 3 style.xml 个

PreferenceActivity class 代码:

@Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        Toolbar bar;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
            bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.pref_toolbar, root, false);
            root.addView(bar, 0);
        } else {
            ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
            ListView content = (ListView) root.getChildAt(0);

            root.removeAllViews();

            bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.pref_toolbar, root, false);


            int height;
            TypedValue tv = new TypedValue();
            if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
                height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
            }else{
                height = bar.getHeight();
            }

            content.setPadding(0, height, 0, 0);

            root.addView(content);
            root.addView(bar);
        }

        bar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

inst_theme(与 v16 相同)

<style name="inst_theme" parent="AppBaseTheme">
        <item name="android:background">@drawable/jrw_back_material_empty</item>
        <item name="android:textColorTertiary">@color/pref_summary</item>
    </style>

inst_theme (v21)

<style name="inst_theme" parent="AppBaseTheme">
        <item name="android:windowBackground">@color/grijswit</item>
        <item name="android:colorPrimary">@color/jumbo_main_2</item>
        <item name="android:colorPrimaryDark">@color/antraciet</item>
        <item name="android:textColorPrimary">@color/pref_name</item>
        <item name="android:textColorSecondary">@color/pref_name</item>
        <item name="android:textColorTertiary">@color/pref_name</item>
        <item name="android:textColor">@color/pref_summary</item>
        <item name="android:preferenceCategoryStyle">@style/pref_style</item>
    </style>

    <style name="pref_style" parent="AppBaseTheme">
        <item name="android:layout">@layout/pref_cat_style</item>
    </style>

pref_cat_style.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/title"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:gravity="center_vertical"
    android:textColor="@color/jumbo_main_2"
    android:textStyle="bold"
    style="@style/TextAppearance.AppCompat.Body1"/>

AppBaseTheme:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">

        </style>

我希望你能帮我解决这个问题,我只是看不出我做错了什么,所有其他样式都被每个 API.

使用得很好

提前谢谢你:)

已修复!

我刚刚将所有样式重命名为 inst_theme
并仅用 @style/inst_theme

引用它们

故事的寓意:三思而后行post