Reputation: 60251
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?
Upvotes: 4
Views: 6177
Reputation: 1012
It's changed a bit, you have to set containerColor
to change background color.
Button(
onClick = { //todo },
colors = ButtonDefaults.buttonColors(
containerColor = Color.Yellow, // your background color
contentColor = Color.Unspecified,// change text color
disabledContainerColor = Color.Unspecified,
disabledContentColor = Color.Unspecified
)
)
Upvotes: 0
Reputation: 364730
You can use the ButtonDefaults.buttonColors
using the backgroundColor
property:
Something like:
Button(
onClick = { },
colors = ButtonDefaults.buttonColors(
backgroundColor = Color.Red)
)
Upvotes: 5
Reputation: 9190
Try this:
Button(
onClick = {},
colors = ButtonConstants.defaultButtonColors(backgroundColor = Color.Yellow)
) {
/**/
}
Upvotes: 6