PreferenceFragmentCompat has padding on PreferenceCategory that I can’t get rid of

Actually there is a better hack to fix this, also with resource overriding:

Create res/values-sw360dp-v13/values-preference.xml:

<?xml version="1.0" encoding="utf-8"?>

<resources xmlns:tools="http://schemas.android.com/tools">
    <bool name="config_materialPreferenceIconSpaceReserved" tools:ignore="MissingDefaultResource,PrivateResource">false</bool>
    <dimen name="preference_category_padding_start" tools:ignore="MissingDefaultResource,PrivateResource">0dp</dimen>
</resources>

The <bool> fixes the default value of iconSpacePreserved for all Preference; The <dimen> fixes the PreferenceCategory.

EDIT: If you are using androidx.preference:preference:1.1.0-alpha01 or above, you won’t need the preference_category_padding_start fix and config_materialPreferenceIconSpaceReserved only will be enough.

Leave a Comment