[英]How to set JetpackCompose Button Background Color
I tried the code in background color on Button in Jetpack Compose我在 Jetpack Compose 中的 Button 上尝试了背景颜色的代码
Button(
onClick = { },
backgroundColor = Color.Yellow) {
}
but it doesn't recognize backgroundColor
anymore.但它不再识别
backgroundColor
了。
I tried the below我尝试了以下
Button(
modifier = Modifier.background(Color.Yellow),
onClick = { }){
}
Doesn't error out but the color is not setting不会出错,但颜色没有设置
I'm using 1.0.0-alpha07
of Jetpack Compose.我正在使用 Jetpack Compose 的
1.0.0-alpha07
。 What's the way to set background color of the button?设置按钮背景颜色的方法是什么?
Try this:尝试这个:
Button(
onClick = {},
colors = ButtonConstants.defaultButtonColors(backgroundColor = Color.Yellow)
) {
/**/
}
With 1.0.0
(tested with 1.0.0-beta08
) you can use the ButtonDefaults.buttonColors
using the backgroundColor
property:使用
1.0.0
(使用1.0.0-beta08
测试),您可以使用ButtonDefaults.buttonColors
使用backgroundColor
属性:
Something like:就像是:
Button(
onClick = { },
colors = ButtonDefaults.buttonColors(
backgroundColor = Color.Red)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.