3

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?

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Elye
  • 53,639
  • 54
  • 212
  • 474

2 Answers2

6

Try this:

Button(
   onClick = {},
   colors = ButtonConstants.defaultButtonColors(backgroundColor = Color.Yellow)
) {
   /**/
}
veritas1
  • 8,740
  • 6
  • 27
  • 37
3

You can use the ButtonDefaults.buttonColors using the backgroundColor property:

Something like:

Button(
     onClick = {  },
     colors = ButtonDefaults.buttonColors(
          backgroundColor = Color.Red)
)
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • 2
    Ref for ButtonDefaults: https://developer.android.com/reference/kotlin/androidx/compose/material3/ButtonDefaults More on Themes: https://developer.android.com/jetpack/compose/themes – dobhareach Jan 25 '22 at 10:28