androidandroid-support-librarypreferencefragmentpreference-v7

PreferenceFragmentCompat padding issue with @style/PreferenceThemeOverlay


While using the default PreferenceThemeOverlay from the preference-v7 support library (version 23.1.0) I ran into the following issue. Starting from API 22 my PreferenceFragmentCompat had an ugly additional padding added to the left and right side of my preference list.

build.gradle:

compile 'com.android.support:appcompat-v7:23.1.0'

styles.xml:

<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>

enter image description here

After I didn't find any helpful solution on stackoverflow I wrote a workaround myself. I just wanted to share with u guys.


Solution

  • It seems the dafault padding is there for API < 22 devices but should not be present in API >= 22. Here is my fix:

    This goes into styles.xml

    <style name="AppTheme" parent="Theme.AppCompat.Light">
    
        ...
    
        <item name="preferenceTheme">@style/AppTheme.FixForPreferenceThemeOverlay</item>
    </style>
    
    <style name="AppTheme.FixForPreferenceThemeOverlay" parent="PreferenceThemeOverlay">
        <item name="preferenceFragmentListStyle">@style/AppTheme.FixForPreferenceFragmentList</item>
    </style>
    <style name="AppTheme.FixForPreferenceFragmentList">
        <item name="android:paddingLeft">0dp</item>
        <item name="android:paddingRight">0dp</item>
    </style>