Тема Android Preference Screen не работает

Я настраиваю экран настроек Androidx с архитектурными компонентами навигации в своем приложении. По какой-то причине экран настроек Android выглядит так

введите здесь описание изображения

Когда я переключаю тему из переключателя тем Android Studio, она выглядит отлично.

введите здесь описание изображения

введите здесь описание изображения

Вот мой код макета Preference XML

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

<PreferenceCategory
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:iconSpaceReserved="false"
    app:singleLineTitle="true"
    app:title="@string/display_language_header">

    <ListPreference
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:entries="@array/Languages"
        app:entryValues="@array/Languages_Values"
        app:icon="@drawable/ic_language"
        app:key="application_language"
        app:singleLineTitle="true"
        app:summary="@string/default_application_language"
        app:title="@string/application_settings_language" />

</PreferenceCategory>

<PreferenceCategory
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:iconSpaceReserved="false"
    app:singleLineTitle="true"
    app:title="@string/normal_settings_title">

    <SwitchPreferenceCompat
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:icon="@drawable/ic_sound"
        app:key="sound_setting"
        app:singleLineTitle="true"
        app:summary="@string/sound_settings_summary"
        app:title="@string/sound_settings_title" />

    <SwitchPreferenceCompat
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:summary="@string/vibration_settings_summary"
        android:title="@string/vibration_settings_title"
        app:icon="@drawable/ic_vibrate"
        app:key="vibration_setting"
        app:singleLineTitle="true" />

    <SwitchPreferenceCompat
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:summary="@string/auto_copy_to_clip_board_settings_summary"
        android:title="@string/auto_copy_to_clipboard_settings_title"
        app:icon="@drawable/ic_copy"
        app:key="copy_to_clip_board_setting"
        app:singleLineTitle="true" />

    <SwitchPreferenceCompat
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:summary="@string/auto_web_search_settings_summary"
        android:title="@string/auto_web_search_settings_title"
        app:icon="@drawable/ic_search"
        app:key="auto_web_search_setting"
        app:singleLineTitle="true" />

    <SwitchPreferenceCompat
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:summary="@string/save_history_settings_summary"
        android:title="@string/save_history_settings_title"
        app:icon="@drawable/ic_save"
        app:key="save_history_setting"
        app:singleLineTitle="true" />
</PreferenceCategory>


<PreferenceCategory
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:iconSpaceReserved="false"
    app:singleLineTitle="true"
    app:title="@string/application_settings_title">

    <Preference
        android:id="@+id/privacy_policy"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:key="privacy_policy"
        android:summary="@string/privacy_policy_settings_summary"
        android:title="@string/privacy_policy_settings_title"
        app:singleLineTitle="true" />


    <Preference
        android:id="@+id/share_with_friends"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:key="share_with_friends"
        android:summary="@string/share_with_friends_summary"
        android:title="@string/share_with_friends_title"
        app:singleLineTitle="true" />


    <Preference
        android:id="@+id/rate_us"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:key="rate_us"
        android:summary="@string/rate_us_summary"
        android:title="@string/rate_us_summary"
        app:singleLineTitle="true" />

    <Preference
        android:id="@+id/delete_history"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:key="delete_history"
        android:summary="@string/delete_history_summary"
        android:title="@string/delete_history_title"
        app:singleLineTitle="true" />


</PreferenceCategory>

Мой стиль приложения

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:colorSecondary">@color/colorPrimary</item>
    <item name="fontFamily">@font/regular</item>
    <item name="android:orientation">vertical</item>
</style>

Я попытался отдать предпочтение жестко закодированной теме экрана, например android:theme=@style/AppTheme, но она тоже не работает. Я вызываю Preference Fragment через нижнюю панель приложений, используя навигационный контроллер. Пожалуйста, помогите мне понять, что я делаю неправильно?


person Muhammad Zubair    schedule 14.09.2020    source источник
comment
Это так только в предварительном просмотре в Android Studio или также при отображении в эмуляторе/устройстве?   -  person cewaphi    schedule 14.09.2020
comment
Нет, также в эмуляторе и реальном устройстве. Я попытался изменить основную тему приложения с материала на Appcombat, но до сих пор нет прогресса.   -  person Muhammad Zubair    schedule 14.09.2020


Ответы (1)


Я нашел исправление для этого ответа. У меня было android:orientation в манифесте Android, из-за чего экран настроек принимал вертикальную ориентацию, а не горизонтальную ориентацию. Теперь это выглядит как обычный экран предпочтений.

person Muhammad Zubair    schedule 10.10.2020