The sample project can be found here
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.
compile 'com.takisoft.fix:preference-v7:27.0.0.0'
You can use either PreferenceFragmentCompat
or PreferenceFragmentCompatDividers
.
(Watch out for the appropriate package name when importing PreferenceFragmentCompat
!)
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>
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