【发布时间】:2017-01-15 15:21:38
【问题描述】:
我在 viewpager 中创建 PreferenceFragment 并收到错误
java.lang.IllegalStateException: Must specify preferenceTheme in theme
我提到了PreferenceFragmentCompat requires preferenceTheme to be set,但无法解决。我添加了我的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>
下面是首屏的代码
<?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>
你能建议一下吗,我是第一次使用主题并且对此感到困惑。仍然出现同样的错误。
【问题讨论】:
标签: java android themes preferencefragment