takisoft / preferencex-android

Android's "androidx.preference" library has some issues, this lib tries to fix them.
Apache License 2.0
55 stars 10 forks source link

How to set dividers with left/right margin + add left/right padding to pref rows? #10

Closed ozmium closed 4 years ago

ozmium commented 4 years ago

On the native Android Preference -- android.preference.Preference -- the preference rows use a divider that has some padding added to the left and right, so that the lines do not go all the way to the edge of the screen.

Also, the native Android Preference has a larger default left and right padding for every list row.

But both the takisoft Preference and the AndroidX library Preference -- androidx.preference.preference do not have the same divider line style and default padding.

Screenshot examples:

Native Android Preference -- android.preference.PreferenceFragment

base_api26_native_pref

AndroidX Library Preference -- androidx.preference.PreferenceFragmentCompat and com.takisoft.preferencex.PreferenceFragmentCompat

base_api26

There is a workaround for the general padding of the rows, taken from here:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    ... ...
    <item name="preferenceTheme">@style/customPreferenceThemeOverlay</item>
</style>

<style name="customPreferenceThemeOverlay" parent="@style/PreferenceThemeOverlay">
    <item name="preferenceFragmentListStyle">@style/customPreferenceFragmentList</item>
</style>

<style name="customPreferenceFragmentList">
    <item name="android:paddingLeft">5dp</item>
    <item name="android:paddingRight">5dp</item>
</style>

But I'm not sure if this is the right approach, because different screen sizes (for example phones and tablets, portrait and landscape) probably had different amounts of padding.

I cannot find a workaround for the divider lines.

So is there a way to make the AndroidX library and takisfot library adopt the same padding styles as the original native preference?


Another perhaps unrelated issue:

These two libraries cause problems with internal Locale/language switching in Android apps, on API 21 (Android 5.0) to 25 (Android 7.1).

implementation "androidx.preference:preference:1.1.0" // version 1.0.0 does not have this problem
implementation 'com.takisoft.preferencex:preferencex:1.1.0'

The problem is discussed here: https://stackoverflow.com/questions/55265834/change-locale-not-work-after-migrate-to-androidx

But is there a way you can fix it internally inside the library?

gregkorossy commented 4 years ago

The material design guidelines' Android settings part shows the dividers as full-length ones, so I'd stick to that instead of some old implementation.

Regarding the locale problem, I think it's related to appcompat so there's not much to do about it in this lib.

ozmium commented 4 years ago

Ah I see. So I asssume the divider line style is intentional, and not a bug.

I will close this issue. Thanks for explaining.