无法找到具有此名称的参数:backgroundColor

huangapple go评论151阅读模式
英文:

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")
    }
}

huangapple
  • 本文由 发表于 2023年6月12日 03:39:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76452238.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定