gpt4 book ai didi

android - Material Theme Colors 导致空白的 Jetpack Compose 按钮

转载 作者:行者123 更新时间:2023-12-04 23:56:08 24 4
gpt4 key购买 nike

具有默认 Material 主题颜色(下面的代码)的简单可组合项产生以下预览图像(在 IDE 和设备上)

@Preview
@Composable
fun PreviewCalendar() {
MaterialTheme {
Column{
Row{Text("Hello World")}
Row{Button(onClick = {}){Text("Hello World Button")} }
}
}
}

Default colors for Material Theme

当提供我自己的颜色时,按钮变为空白(下面的代码和屏幕截图)。阅读 Button 的源代码,我希望按钮的背景色是 primary。我是否错误地使用了我的颜色?我找不到类似行为的错误报告

val lightTheme = 
Colors(
primary = Color(0x0d47a1),
primaryVariant = Color(0x5472d3),
secondary = Color(0x212121),
secondaryVariant = Color(0x484848),
background = Color(0xffffff),
surface = Color(0xffffff),
error = Color(0xB00020),
onPrimary = Color(0xffffff),
onSecondary = Color(0xffffff),
onBackground = Color(0x000000),
onSurface = Color(0x000000),
onError = Color(0xffffff),
isLight = true
)

@Preview
@Composable
fun PreviewCalendar() {
MaterialTheme(colors = lightTheme) {
Column{
Row{Text("Hello World")}
Row{Button(onClick = {}){Text("Hello World Button")} }
}
}
}

Custom colors for Material Theme

最佳答案

我使用谷歌的 Material 主题工具生成了这些颜色,但没有注意到 Compose 正在寻找 ARGB 颜色空间。我指定的所有颜色的 alpha 值为 0,因此是透明的。正确的颜色是:

val lightTheme = 
Colors(
primary = Color(0xFF0d47a1),
primaryVariant = Color(0xFF5472d3),
secondary = Color(0xFF212121),
secondaryVariant = Color(0xFF484848),
background = Color(0xFFffffff),
surface = Color(0xFFffffff),
error = Color(0xFFB00020),
onPrimary = Color(0xFFffffff),
onSecondary = Color(0xFFffffff),
onBackground = Color(0xFF000000),
onSurface = Color(0xFF000000),
onError = Color(0xFFffffff),
isLight = true
)

关于android - Material Theme Colors 导致空白的 Jetpack Compose 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66520940/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com