[英]Default color of TopAppBar in jetpack compose material3
I find that the default color of TopAppBar in my project is white (in light mode), while normally it should has another default color, like in document .我发现我的项目中 TopAppBar 的默认颜色是白色(在浅色模式下),而通常它应该有另一种默认颜色,比如在document中。
I notice that the default color in code is:我注意到代码中的默认颜色是:
@Composable
fun TopAppBar(
colors: TopAppBarColors = TopAppBarDefaults.smallTopAppBarColors(),
...
)
@Composable
fun smallTopAppBarColors(
containerColor: Color = TopAppBarSmallTokens.ContainerColor.toColor(),
...
)
internal object TopAppBarSmallTokens {
val ContainerColor = ColorSchemeKeyTokens.Surface
...
}
which is the same as that of BottomAppBar, ColorSchemeKeyTokens.Surface
:与
ColorSchemeKeyTokens.Surface
的 ColorSchemeKeyTokens.Surface 相同:
@Composable
fun BottomAppBar(
containerColor: Color = BottomAppBarDefaults.containerColor,
...
)
object BottomAppBarDefaults {
val containerColor: Color @Composable get() = BottomAppBarTokens.ContainerColor.toColor()
...
}
internal object BottomAppBarTokens {
val ContainerColor = ColorSchemeKeyTokens.Surface
...
}
But in my test, container color of TopAppBar
is the same as document shows, while container color of TopAppBar
is another: white.但在我的测试中,
TopAppBar
的容器颜色与文档显示的相同,而TopAppBar
的容器颜色是另一种:白色。
I can't figured out what causes the default color of TopAppBar to turn into white.我不知道是什么原因导致 TopAppBar 的默认颜色变成白色。
Versions of libraies:图书馆的版本:
The default background color in M3 TopAppBar
is based on containerColor
attribute defined in the colors
attribute. M3
TopAppBar
中的默认背景颜色基于colors
属性中定义的containerColor
属性。
The default color is val ContainerColor = ColorSchemeKeyTokens.Surface
.默认颜色是
val ContainerColor = ColorSchemeKeyTokens.Surface
。
Check in your theme.检查你的主题。 If the
surface
color is omitted the Light scheme default value is: #FFFBFE
as described in the doc .如果省略
surface
颜色,则光方案默认值为: #FFFBFE
,如文档中所述。
You can check in the code:您可以签入代码:
val Surface = PaletteTokens.Neutral99
val Neutral99 = Color(red = 255, green = 251, blue = 254)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.