如何更改 Material 3 android xml 的警报对话框的颜色

问题描述 投票:0回答:1

我想更改材质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()
android-layout android-alertdialog material3
1个回答
0
投票

您可以为对话框创建自定义主题

<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)
© www.soinside.com 2019 - 2024. All rights reserved.