我想更改材质3警报对话框的容器颜色
我尝试使用官方文档中的东西 但我无法更改颜色,容器的背景颜色仍然是粉红色/紫色 我正在创建这样的警报对话框,并且有 .setTheme 或 .setBackground 方法
MaterialAlertDialogBuilder(itemView.context as AppCompatActivity)
.setTitle("Do the thing")
.setMessage("Are you sure you want to do the thing?")
.setNeutralButton("Cancel") { dialog, which ->
}
.setPositiveButton("Do") { dialog, which ->
doThing()
}
.show()
您可以为对话框创建自定义主题
<style name="CustomAlertDialogTheme" parent="Theme.Material3.DayNight.Dialog.Alert">
<item name="colorSurface">@color/new_color</item>
</style>
然后设置
MaterialAlertDialogBuilder(itemView.context as AppCompatActivity, R.style.CustomAlertDialogTheme)