Skip to content

Instantly share code, notes, and snippets.

@huhuang03
Created August 12, 2020 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huhuang03/5911eb8f9c75736d9510d1813be3c608 to your computer and use it in GitHub Desktop.
Save huhuang03/5911eb8f9c75736d9510d1813be3c608 to your computer and use it in GitHub Desktop.
Android: How to remove margin/padding in Preference Screen
https://stackoverflow.com/questions/18509369/android-how-to-remove-margin-padding-in-preference-screen
Simple working solution from here.
It works across all preferences without need write to all preferences app:iconSpaceReserved="false"
Create res/values-sw360dp/values-preference.xml:
<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.1, you won't need the dimen preference_category_padding_start. Tested on Android 6-10.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment