Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PreferenceFragmentCompat requires preferenceTheme to be set

The sample project can be found here

The bugfix is available as a gradle dependency

Download

Now one can use the library pretty easy. Here are quickest way to do so, but you should check out the README for more info.

1. Update your module's gradle file:

compile 'com.takisoft.fix:preference-v7:27.0.0.0'

2. Use the appropriate class as your fragment's base

You can use either PreferenceFragmentCompat or PreferenceFragmentCompatDividers.

(Watch out for the appropriate package name when importing PreferenceFragmentCompat!)

3. Use the appropriate theme

Set your containing Activity's theme to a variant of @style/PreferenceFixTheme, like NoActionBar, Light, etc.

For more info and usage tips, go to the project's page.


P.S. In this section you could find the detailed solution that led to creation of the library, but I decided to remove it because it might be confusing. If you're curious about the steps, you can still find them in the revision history of this answer.


You have to specify preferenceTheme in your preference activity's theme.

For example :

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

PreferenceThemeOverlay is the default theme which comes with preference-v7 support library.


Seems like Google fixed this issue. I've tested this with the preference v14-support version 25.3.1

1) Add implementation 'com.android.support:preference-v14:25.3.1' to your Gradle.

2) Add PreferenceThemeOverlay.v14.Material to the style instead of PreferenceThemeOverlay.

<style name="AppTheme.SettingsTheme" parent="AppTheme.NoActionBar">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>

3) Finally, add the style to the Manifest

android:theme="@style/AppTheme.SettingsTheme"

To use the PreferenceFragmentCompat you have to set preferenceTheme in your theme:

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

In this way you can customize the preferenceTheme to style the layouts used for each preference type without affecting other parts of your Activity.


I just added this line in theme and it working perfect on API 19 and above.

<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>