Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.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
Java 如何将主题应用于首选项屏幕_Java_Android_Themes_Preferencefragment - Fatal编程技术网

Java 如何将主题应用于首选项屏幕

Java 如何将主题应用于首选项屏幕,java,android,themes,preferencefragment,Java,Android,Themes,Preferencefragment,我正在viewpager中创建PreferenceFragment,并得到错误信息 java.lang.IllegalStateException: Must specify preferenceTheme in theme 我提到了,但没能解决。我添加了styles.xml,如下所示 <resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme

我正在viewpager中创建PreferenceFragment,并得到错误信息

java.lang.IllegalStateException: Must specify preferenceTheme in theme
我提到了,但没能解决。我添加了styles.xml,如下所示

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:preferenceStyle">@style/PreferenceThemeOverlay</item>
    </style>

    <style name="SettingsTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
    </style>
</resources>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
@样式/首选项最低限度
@样式/首选项最低限度
下面是清单的代码

  <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity"
            android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

下面是pref屏幕的代码

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="screen">

    <SwitchPreference
        android:key="sc"
        android:summary="Hi"
        android:title="Hello" />

</PreferenceScreen>


你能给我一个建议吗,我第一次使用这个主题,我对它感到困惑。仍然出现相同的错误。

清单中的活动标记中尝试此操作:

<activity android:name=".MainActivity"
        android:theme="@style/AppTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
而不是:

<item name="android:preferenceStyle">@style/PreferenceThemeOverlay</item>

新错误:java.lang.RuntimeException:无法启动活动组件信息{jss.fragments/jss.fragments.MainActivity}:java.lang.IllegalStateException:此活动已具有由窗口装饰提供的操作栏。不要请求Window.FEATURE\u SUPPORT\u ACTION\u工具栏,并在主题中将windowActionBar设置为false以使用工具栏。
<item name="android:preferenceStyle">@style/PreferenceThemeOverlay</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>