如何更改ListPreference按钮的颜色?

时间:2019-04-03 21:17:57

标签: android android-styles listpreference material-components-android

我使用波纹管样式将对话框背景颜色更改为深色,在首选项页面中,我使用ListPreference,并且在应用此样式后,ListPreference的cancel按钮在对话框背景中消失了。

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

是否可以更改此按钮的颜色?

ListPreference

1 个答案:

答案 0 :(得分:0)

最后我找到了解决方案。我不了解android:alertDialogThemealertDialogTheme(没有android:)之间有什么区别,但是首选项屏幕使用alertDialogTheme来样式化对话框。 通过将波纹管项目添加到AppThemeBase,我的问题得以解决。

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

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