我从'Theme.AppCompat.Light.NoActionBar'延伸出来,我不想把我的AppTheme切换到MaterialDesign上。
MaterialAlertDialogBuilder(context, R.style.MaterialDialog)
.setCancelable(false)
.setMessage(message)
.setPositiveButton("OK") { dialog, _ -> dialog.dismiss() }
.show()
<style name="MaterialDialog" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorSurface">#ffffff</item>
</style>
预期的
结果:我从'Theme.AppCompat.Light.NoActionBar'延伸出来,我不想把我的AppTheme切换到MaterialDesign MaterialAlertDialogBuilder(context, R.style.Material)。
如果你不能移动到一个Material Components主题,你应该使用一个 桥梁主题. 类似的东西。
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<item name="colorSurface">#ffffff</item>
...
</style>
然后在你的代码中使用:
MaterialAlertDialogBuilder(context)
.setCancelable(false)
...
如果你只想覆盖对话框的颜色,只需使用:
MaterialAlertDialogBuilder(context,R.style.MaterialDialog)
.setCancelable(false)
...
with:
<style name="MaterialDialog" parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="materialThemeOverlay">@style/AlertDialogOverlay</item>
</style>
<style name="AlertDialogOverlay">
<item name="colorOnSurface">@color/....</item>
<item name="colorSurface">#ffffff</item>
<item name="colorPrimary">@color/.....</item>
....
</style>