Search code examples
androidandroid-jetpack-composeandroid-buttonandroid-compose-buttonandroid-jetpack-compose-button

How to set JetpackCompose Button Background Color


I tried the code in background color on Button in Jetpack Compose

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

but it doesn't recognize backgroundColor anymore.

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. What's the way to set background color of the button?


Solution

  • Try this:

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