androidandroid-styleslistpreferencematerial-components-android

How to change ListPreference button colors?


I use bellow style to change Dialog background color to dark, In preference page I use ListPreference and after apply this style, cancel button of ListPreference disappeared in dialog background.

<style name="AppThemeBase" parent="Theme.MaterialComponents.DayNight">
    <item name="colorPrimary">#212D3B</item>
    <item name="colorPrimaryDark">#172331</item>
    <item name="colorAccent">#61A3D7</item>
    <item name="android:textColorPrimary">#FFFFFF</item>
    <item name="android:dialogTheme">@style/AppTheme.Dialog</item>
    <item name="android:alertDialogTheme">@style/AppTheme.Dialog</item>
</style>

<style name="AppTheme.Dialog" parent="Theme.MaterialComponents.DayNight.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:background">#212D3B</item>
    <item name="colorPrimary">#61A3D7</item>
    <item name="colorPrimaryDark">#8DB2D3</item>
    <item name="colorAccent">#61A3D7</item>
</style>

Is there a way to change this button color?

ListPreference


Solution

  • Finally I found solution. I don't understand what is different between android:alertDialogTheme and alertDialogTheme (without android:) but preference screen used the alertDialogTheme to stylize dialogs. By adding bellow item to AppThemeBase, my problem is resolved.

    <item name="alertDialogTheme">@style/AppTheme.Dialog</item> 
    

    Final AppThemeBase :

    <style name="AppThemeBase" parent="Theme.MaterialComponents.DayNight">
        <item name="colorPrimary">#212D3B</item>
        <item name="colorPrimaryDark">#172331</item>
        <item name="colorAccent">#61A3D7</item>
        <item name="android:textColorPrimary">#FFFFFF</item>
        <item name="android:dialogTheme">@style/AppTheme.Dialog</item>
        <item name="android:alertDialogTheme">@style/AppTheme.Dialog</item>
        <item name="alertDialogTheme">@style/AppTheme.Dialog</item>
    </style>
    
    <style name="AppTheme.Dialog" parent="Theme.MaterialComponents.DayNight.Dialog">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:background">#212D3B</item>
        <item name="colorPrimary">#61A3D7</item>
        <item name="colorPrimaryDark">#8DB2D3</item>
        <item name="colorAccent">#61A3D7</item>
    </style>