我使用波纹管样式将对话框背景颜色更改为深色,在首选项页面中,我使用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>
是否可以更改此按钮的颜色?
答案 0 :(得分:0)
最后我找到了解决方案。我不了解android:alertDialogTheme
和alertDialogTheme
(没有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>