Search code examples
androidandroid-support-libraryandroid-preferences

Android preference headers margins on pre Lollipop devices


I have an app that makes use of Android preference headers to build an activity that allows to select preferences category to configure. The definition is done in a classic XML file:

<preference-headers xmlns:android="http://schemas.android.com/apk/res/android">

    <header
        android:fragment="app.medicalid.activities.settings.SettingsActivity$AlertsPreferenceFragment"
        android:icon="@drawable/ic_sms_black_24dp"
        android:title="@string/pref_header_alerts" />

    <header
        android:icon="@drawable/ic_sync_black_24dp"
        android:title="@string/pref_header_backup" />

    <header
        android:fragment="app.medicalid.activities.settings.SettingsActivity$LockscreenPreferenceFragment"
        android:icon="@drawable/ic_screen_lock_portrait_black_24dp"
        android:title="@string/pref_header_lock_screen" />

    <header
        android:fragment="app.medicalid.activities.settings.SettingsActivity$SecurityPreferenceFragment"
        android:icon="@drawable/ic_lock_outline_black_24dp"
        android:title="@string/pref_header_security" />

    <header
        android:fragment="app.medicalid.activities.settings.SettingsActivity$AdvancedPreferenceFragment"
        android:icon="@drawable/ic_bug_report_black_24dp"
        android:title="@string/pref_header_advanced" />

</preference-headers>

Below is an exemple of the user interface on pre Lollipop devices on the left and Lollipop+ on the right:

Android PreferenceScreen margins on pre Lollipop devices

My issue is about the left and right margin that is added on pre Lollipop devices. I am looking for a mean to get rid of this left and right margin in order to get something similar to what is displayed on Lollipop+ devices in terms of spaces.

I get the same behaviour with PreferenceScreen.

Any idea is welcome :)


Solution

  • Try to manually set listview padding to 0.

    ListView lv = (ListView) v.findViewById(android.R.id.list);
    lv.setPadding(0, 0, 0, 0);