Material Design 3“colorSurface”受“colorPrimary”影响

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

我正在尝试通过设置

colorSurface
属性(如 documentation 中所述)来更改对话框和底部工作表的背景颜色,但是我在运行应用程序时看到的颜色与颜色不同我在代码中设置。

假设我想要一个具有white background的对话框,所以我写了下面的代码:

<style name="AppTheme" parent="Theme.Material3.Light.NoActionBar">
    <item name="colorPrimary">#FF0000</item>
    <item name="colorSecondary">#DD0000</item>
    <item name="colorSurface">#FFFFFF</item>
</style>

或:

<style name="AppTheme" parent="Theme.Material3.Light.NoActionBar">
    <item name="colorPrimary">#FF0000</item>
    <item name="colorSecondary">#DD0000</item>
    <item name="colorSurface">#FFFFFF</item>
    <item name="materialAlertDialogTheme">@style/ThemeOverlay.AlertDialog</item>
</style>

<style name="ThemeOverlay.AlertDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog">
    <item name="colorSurface">#FFFFFF</item>
</style>

我使用这段代码显示对话框:

MaterialAlertDialogBuilder(this)
    .setTitle("Title")
    .setMessage("Message")
    .setNegativeButton("Positive") { _, _ -> }
    .setPositiveButton("Negative") { _, _ -> }
    .show()

结果是一个带有粉红色背景颜色的对话框,这似乎是因为

colorPrimary
是红色的。同样,如果我将
#000000
设置为
colorSurface
,我不会得到纯黑色背景。当我尝试设置底页的背景时,也会发生同样的事情。

为什么会这样? 是否记录了此行为并且可以将其禁用?

谢谢!

android material-design
© www.soinside.com 2019 - 2024. All rights reserved.