问题
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