【问题标题】:How to set JetpackCompose Button Background Color如何设置 JetpackCompose 按钮​​背景颜色
【发布时间】:2020-11-22 10:54:53
【问题描述】:

我试过background color on Button in Jetpack Compose中的代码

Button(
    onClick = {  },
    backgroundColor = Color.Yellow) {
}

但它不再识别backgroundColor

我尝试了以下

Button(
    modifier = Modifier.background(Color.Yellow),
    onClick = { }){
}

不会出错但颜色未设置

我正在使用 Jetpack Compose 的 1.0.0-alpha07。设置按钮背景颜色的方法是什么?

【问题讨论】:

    标签: android android-button android-jetpack-compose


    【解决方案1】:

    试试这个:

    Button(
       onClick = {},
       colors = ButtonConstants.defaultButtonColors(backgroundColor = Color.Yellow)
    ) {
       /**/
    }
    

    【讨论】:

      【解决方案2】:

      您可以通过backgroundColor 属性使用ButtonDefaults.buttonColors

      类似:

      Button(
           onClick = {  },
           colors = ButtonDefaults.buttonColors(
                backgroundColor = Color.Red)
      )
      
      猜你喜欢
      • 2019-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      • 1970-01-01
      • 2010-09-27
      相关资源
      最近更新 更多