I am trying to figure out why I am getting this error:
java.lang.IllegalStateException: Must specify preferenceTheme in theme
at android.support.v7.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:210)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2177)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager
When trying to run my PreferenceFragmentCompat This is the above class code:
public class SettingsFragment extends PreferenceFragmentCompat {
public SettingsFragment() {
// Required empty public constructor
}
public static SettingsFragment newInstance() {
SettingsFragment fragment = new SettingsFragment();
return fragment;
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.settings_preferences, rootKey);
}
}
This is the activity's manifest declaration that shows the fragment
<activity
android:name=".active_minutes_screen.view.ActiveMinutesActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Code that shows the fragment in the above MainActivity
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, HistoryFragment.newInstance());
ft.commit();
Theme that I am applying via the MainActivity
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>
Thanks to the solution that @Panther suggested. All I had to do is to add this line <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
to my Application Theme and not just the theme of the individual activity that is showing my PreferenceFragment like that:
<!-- 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="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>
Alternatively you can use
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
to achieve modern material look.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With