Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 218
Elye Avatar asked Oct 19 '25 13:10

Elye


2 Answers

Try this:

Button(
   onClick = {},
   colors = ButtonConstants.defaultButtonColors(backgroundColor = Color.Yellow)
) {
   /**/
}
like image 178
veritas1 Avatar answered Oct 21 '25 04:10

veritas1


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

Something like:

Button(
     onClick = {  },
     colors = ButtonDefaults.buttonColors(
          backgroundColor = Color.Red)
)
like image 35
Gabriele Mariotti Avatar answered Oct 21 '25 03:10

Gabriele Mariotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!