[英]Material Design 3 uses colorPrimary for actionBar, navBar and calendar background color. How do I disable this?
After upgrading to Material Design 3, I noticed that the background colors of certain things changed to a faded version of whatever my primary color is set to.升级到 Material Design 3 后,我注意到某些东西的背景 colors 变成了我的原色设置的褪色版本。 For example, if I set my primary color to Red, the navBar and Calendar are now somewhat pink.
例如,如果我将原色设置为红色,则导航栏和日历现在有点粉红色。
<style name="AppTheme" parent="Base.AppTheme" />
<style name="Base.AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
<item name="colorPrimary">@color/red</item>
</style>
I don't know why Material Design assumes that I want these background colors. My design documents require a white background, and setting the primary color to white is not an option.我不知道为什么 Material Design 假设我想要这些背景 colors。我的设计文档需要白色背景,并且不能将原色设置为白色。 If I don't set a primary color at all, it defaults to purple!
如果我根本不设置原色,它默认为紫色!
I had some luck with navBar, because you can set the background color of each item, but no luck with the calendar.我在 navBar 上运气不错,因为你可以设置每个项目的背景颜色,但在日历上就不行了。 I've tried setting everything that sounds color related on a calendar style.
我试过在日历样式上设置听起来与颜色相关的所有内容。 So far nothing changes the calendar background except primaryColor.
到目前为止,除了 primaryColor 之外没有任何改变日历背景。 backgroundColor, backgroundTint, etc. Nothing has worked.
backgroundColor、backgroundTint 等。没有任何效果。 Does anyone know how to override this behavior on Material Design 3?
有谁知道如何在 Material Design 3 上覆盖此行为?
I simply want to set my colorPrimary to green and set the background colors of actionBar, navBar, and calendar to white.我只想将我的 colorPrimary 设置为绿色,并将 actionBar、navBar 和日历的背景 colors 设置为白色。
According to documentation and what i've tested, it seems material theme automatically find matching colors for you haven't specified.根据文档和我测试过的内容,材料主题似乎会自动为您未指定的匹配项 colors 找到匹配项。 I've made a simple reproducer to show you the problem.
我制作了一个简单的复制器来向您展示问题。
colorPrimary
set:colorPrimary
:<style name="Base.AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
<item name="colorPrimary">@color/red1</item>
</style>
<color name="red1">#FB1100</color>
You can see theme set every color for you您可以看到为您设置的每种颜色的主题
In your case, i believe you have to set your own colors in the correct theme field, like the following example.在您的情况下,我相信您必须在正确的主题字段中设置自己的 colors,如下例所示。
I've made a POC to test behavior (I know colors don't match Material Guidelines, but it's for test purpose only) Here you can see i've theme colors matching what i've set, and not what Material theme want.我制作了一个 POC 来测试行为(我知道 colors 与 Material Guidelines 不匹配,但它仅用于测试目的)在这里你可以看到我的主题 colors 与我设置的匹配,而不是 Material 主题想要的。
<style name="Base.AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
<item name="colorPrimary">@color/red1</item>
<item name="colorOnPrimary">@color/red2</item>
<item name="colorPrimaryContainer">@color/red3</item>
<item name="colorOnPrimaryContainer">@color/red4</item>
<item name="colorPrimaryInverse">@color/red5</item>
<item name="colorSecondary">@color/yellow1</item>
<item name="colorOnSecondary">@color/yellow2</item>
<item name="colorSecondaryContainer">@color/yellow3</item>
<item name="colorOnSecondaryContainer">@color/yellow4</item>
<item name="colorTertiary">@color/green1</item>
<item name="colorOnTertiary">@color/green2</item>
<item name="colorTertiaryContainer">@color/green3</item>
<item name="colorOnTertiaryContainer">@color/green4</item>
<item name="android:colorBackground">@color/blue1</item>
<item name="colorOnBackground">@color/blue2</item>
<item name="colorSurface">@color/purple1</item>
<item name="colorOnSurface">@color/purple2</item>
<item name="colorSurfaceVariant">@color/purple3</item>
<item name="colorOnSurfaceVariant">@color/purple4</item>
<item name="colorSurfaceInverse">@color/purple5</item>
<item name="colorOnSurfaceInverse">@color/purple6</item>
</style>
<color name="red1">#FB1100</color>
<color name="red2">#FD3A2C</color>
<color name="red3">#FD6459</color>
<color name="red4">#FF9189</color>
<color name="red5">#FFBABA</color>
<color name="yellow1">#FFC800</color>
<color name="yellow2">#FFDC5C</color>
<color name="yellow3">#FFE896</color>
<color name="yellow4">#FFEEAF</color>
<color name="green1">#4FCA00</color>
<color name="green2">#8EFF46</color>
<color name="green3">#ADFF79</color>
<color name="green4">#C8FFA6</color>
<color name="blue1">#0048FF</color>
<color name="blue2">#487CFF</color>
<color name="purple1">#9500FF</color>
<color name="purple2">#AD3AFF</color>
<color name="purple3">#C169FF</color>
<color name="purple4">#D8A1FF</color>
<color name="purple5">#E6C2FF</color>
<color name="purple6">#F3E1FF</color>
Here you can see every color used by my components is sourced from my theme, and not by Material itself.在这里您可以看到我的组件使用的每种颜色都来自我的主题,而不是 Material 本身。 (I know its cringy with theses colors, but I made it on purpose to identify behaviors for each field category (primary, secondary, tertiary, background, surface, etc)
(我知道论文 colors 令人毛骨悚然,但我故意这样做是为了识别每个字段类别(主要、次要、第三、背景、表面等)的行为
Disclaimer: I don't have your code so i can't tell you exactly which field you have to set, but you could easily use my values to find out which one is used to color your component
免责声明:我没有你的代码,所以我不能确切地告诉你你必须设置哪个字段,但你可以很容易地使用我的值来找出哪个用于为你的组件着色
Again, here is the documentation where you can find every field and its default value for Material default theme.同样,这里是文档,您可以在其中找到 Material 默认主题的每个字段及其默认值。
Hope this help you fix your problem, and if you need more help, please provide a minimal reproducer so we can try with the exact same config.希望这可以帮助您解决问题,如果您需要更多帮助,请提供一个最小的复制器,以便我们可以尝试使用完全相同的配置。
Have a nice day !祝你今天过得愉快 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.