PreferenceFragmentCompat padding issue with @style/PreferenceThemeOverlay
Asked Answered
W

1

2

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.

Wren answered 18/10, 2015 at 12:39 Comment(0)
W
5

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>
Wren answered 18/10, 2015 at 12:39 Comment(2)
Suggest that AppTheme.FixForPreferenceFragmentList has parent="@style/PreferenceFragmentList"Bopp
Also adding <item name="android:paddingStart">0dp</item> and <item name="android:paddingEnd">0dp</item> to the List style as well.Bopp

© 2022 - 2024 — McMap. All rights reserved.