AndroidX Preference Screen shifted off center [duplicate]

為{幸葍}努か 提交于 2020-07-18 07:21:28

问题


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>


回答1:


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>


来源:https://stackoverflow.com/questions/55371906/androidx-preference-screen-shifted-off-center

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!