androiduinavigationcontrollerpreferencescreenbottombar

Android Preference Screen theme not working


I am setting up an Androidx Preference Screen with Navigation Architectural Components in my Application. For some reason, Android Preference Screen Looks like this

enter image description here

When I switch the theme from the Android Studio theme switcher, It looks perfectly fine.

enter image description here

enter image description here

Here's my Preference XML layout code

<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>

My Application Style

<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>

I tried to give preference screen hardcoded theme like android:theme="@style/AppTheme" but it's not working either. I'm calling Preference Fragment through the Bottom App Bar using navigation controller. Please help me understand what's that I am doing wrong?


Solution

  • I found a fix to this answer. I had android:orientation in the Android Manifest, which was causing the Preference screen to take the vertical orientation instead of horizontal orientation. Now It looks like a normal preference screen.