yigitserin
yigitserin

Reputation: 611

PreferenceFragmentCompat style is broken after setting targetSdkVersion to 28.

Hey there my PreferenceFragmentCompat looked fine before I upgraded to sdk version 28. However after upgrading, its style is broken and I can't seem to fix it. Why is the reason and how can I fix it?

This is my app style:

<style name="MyMaterialTheme0" parent="MyMaterialTheme0.Base"/>

<style name="MyMaterialTheme0.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/colorPrimary0</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark0</item>
    <item name="colorAccent">@color/colorAccent0</item>
    <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>

Old style Old style New Broken style New broken style

Upvotes: 0

Views: 874

Answers (2)

prot0n
prot0n

Reputation: 193

Here are the diff changes between the PreferenceThemeOverlay.v14.Material and PreferenceThemeOverlay. Pay attention to new allowDividerAbove, allowDividerBelow and iconSpaceReserved attributes. I've had to modify my style to match before update like:

<style name="AppSettingsTheme" parent="PreferenceThemeOverlay">
    <item name="preferenceCategoryStyle">@style/AppSettings.Category.Material</item>
    <item name="preferenceFragmentCompatStyle">@style/AppSettings.Fragment.Material</item>
    <item name="preferenceStyle">@style/AppSettings.Preference.Material</item>
</style>

<style name="AppSettings.Category.Material" parent="Preference.Category.Material">
    <item name="allowDividerAbove">false</item>
    <item name="allowDividerBelow">false</item>
    <item name="iconSpaceReserved">false</item>
</style>

<style name="AppSettings.Fragment.Material" parent="PreferenceFragment.Material">
    <item name="allowDividerAfterLastItem">true</item>
</style>

<style name="AppSettings.Preference.Material" parent="Preference.Material">
    <item name="allowDividerAbove">true</item>
    <item name="allowDividerBelow">true</item>
    <item name="iconSpaceReserved">false</item>
</style>

and update your preferenceTheme to @style/AppSettingsTheme value instead of @style/PreferenceThemeOverlay.v14.Material

Upvotes: 1

ianhanniballake
ianhanniballake

Reputation: 200100

Per the Preference rc01 release notes:

  • PreferenceThemeOverlay has been updated to the latest material theme. If no custom theme is provided, PreferenceThemeOverlay is used as the default theme.
  • PreferenceThemeOverlay.v14 and PreferenceThemeOverlay.v14.Material themes have been deprecated in favour of PreferenceThemeOverlay.

Therefore you can simply remove your preferenceTheme attribute entirely to get the default, correct theming if you're not customizing the preferences theme at all.

Upvotes: 0

Related Questions