PreferenceFragmentCompat padding issue with @style/PreferenceThemeOverlay

流过昼夜 提交于 2020-01-13 06:17:07

问题


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>

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


回答1:


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>


来源:https://stackoverflow.com/questions/33198014/preferencefragmentcompat-padding-issue-with-style-preferencethemeoverlay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!