英文:
Cannot find a parameter with this name: backgroundColor
问题
要更改按钮的背景颜色。但它给我一个错误,说“找不到具有此名称的参数:backgroundColor”。
Button(onClick = { /*TODO*/ },
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Yellow),
) {
Text(
text = "按钮",
)
}
英文:
I want to change background color of a button. But it gives me "Cannot find a parameter with this name: backgroundColor" error.
Button(onClick = { /*TODO*/ },
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Yellow),
) {
Text(
text = "Button",
)
}
答案1
得分: 2
可能是因为您正在使用Material 3,因此参数的命名不同:
colors = ButtonDefaults.buttonColors(
containerColor = Color.Yellow,
contentColor = // 选择您的颜色)
英文:
It may be because you are using Material 3, in which case the naming of parameters is different:
colors = ButtonDefaults.buttonColors(
containerColor = Color.Yellow,
contentColor = // choose your color)
答案2
得分: 0
在 android-jetpack-compose
中,Button 组件没有名为 backgroundColor
的参数。您可以通过将 Button 组件包装在一个 Box 内,并为该 Box 设置背景颜色来更改背景:
Box(
modifier = Modifier
.background(Color.Yellow)
.padding(8.dp)
) {
Button(
onClick = { /* TODO */ },
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Transparent),
) {
Text(text = "Button")
}
}
英文:
In android-jetpack-compose
, the Button component does not have a parameter called backgroundColor
. You can change the background by wrapping the Button component inside a Box and setting the background colour for the Box:
Box(
modifier = Modifier
.background(Color.Yellow)
.padding(8.dp)
) {
Button(
onClick = { /* TODO */ },
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Transparent),
) {
Text(text = "Button")
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论