Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将错误主题应用于具有xml引用的PreferenceActivity_Android_Xml_Reference_Themes_Android Preferences - Fatal编程技术网

Android 将错误主题应用于具有xml引用的PreferenceActivity

Android 将错误主题应用于具有xml引用的PreferenceActivity,android,xml,reference,themes,android-preferences,Android,Xml,Reference,Themes,Android Preferences,当我使用XML引用引用所述主题时,我似乎在将主题实现到PreferenceActivity上时遇到问题。 我有3个style.xml style.xml style.xml(v16) style.xml(v21) 每一个都在其相应的值目录中。 要应用该主题,我在清单中使用?attr/inst_主题引用它 我当然会引用inst_theme作为主题名。 这在API 16中非常有效 但是…… 当我在API 21上尝试主题时,它看起来是这样的。 但它应该是这样的 我通过更改V21 inst_主题名称

当我使用XML引用引用所述主题时,我似乎在将主题实现到PreferenceActivity上时遇到问题。
我有3个style.xml

  • style.xml
  • style.xml(v16)
  • style.xml(v21)
    每一个都在其相应的值目录中。
    要应用该主题,我在清单中使用
    ?attr/inst_主题引用它

    我当然会引用
    inst_theme
    作为主题名。 这在API 16中非常有效 但是……
    当我在API 21上尝试主题时,它看起来是这样的。

    但它应该是这样的 我通过更改V21 inst_主题名称并在清单中使用@style/inst_主题来实现这一点
    另一个但是…
    同时在API 16上使用以下设置:

    这其实不需要澄清。
    我根据自己的喜好设置活动
首选项活动类别代码:

@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();
            }
        });
    }
安装主题(与v16相同)


@可拉伸/jrw\u背面\u材料\u空
@颜色/首选项摘要
inst_主题(v21)


@颜色/灰白色
@彩色/巨型主机2
@彩色/反彩色
@颜色/首选名称
@颜色/首选名称
@颜色/首选名称
@颜色/首选项摘要
@样式/首选样式
@布局/首选类别样式
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\u theme

并用
@style/inst_主题引用它们

这个故事的寓意是:发帖前先想一想

<?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"/>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">

        </style>