Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidX Preference Screen shifted off center [duplicate]

I have a preference screen in my app and it is shifted off center and the header text or data doesn't start from the left shown in the image below. I am initializing the settings fragment. I have not applied any visual changes or added any special attributes.

There is no padding or margin in the parent activity. I also have a recycler view which is displayed perfectly fine in the app with it being off centered

This is my preferences.xml file

<androidx.preference.PreferenceScreen
xmlns:app="http://schemas.android.com/apk/res-auto">

    <PreferenceCategory
        app:title="General">
        <Preference
            app:key="feedback"
            app:title="Send Feedback"
            app:summary="Report technical issues or suggest new features"/>
        <Preference
            app:key="about"
            app:title="About Us"/>
    </PreferenceCategory>


    <PreferenceCategory
        app:title="Customize">

        <SwitchPreferenceCompat
            app:key="@string/key_darkTheme"
            app:title="Enable Dark Theme"
            app:summary="Enable dark theme throughout app (Restarts App Automatically)"
            app:defaultValue="false"/>

        <ListPreference
            app:key="@string/key_font"
            app:title="Set Font Size"
            app:entries="@array/settings_list_preference_font"
            app:entryValues="@array/settings_list_preference_values"
            app:defaultValue="2"
            app:summary="Set font size according to your liking"/>


    </PreferenceCategory>

</androidx.preference.PreferenceScreen>

Preference Screen off center

like image 620
Sukrit Kumar Avatar asked Jan 01 '23 03:01

Sukrit Kumar


1 Answers

Probably because the preference automatically give you a space for an icon. You can disable that by disabling the space using app:iconSpaceReserved="false" in each element.

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

  <PreferenceCategory
      android:title="your_title"
      app:iconSpaceReserved="false">

     ...

  </PreferenceCategory>

</PreferenceScreen>
like image 92
Pavel Poley Avatar answered Jan 13 '23 11:01

Pavel Poley