0

I've tried to set the background color of buttons with custom hex values:

colors.xml:

    <color name="red">#F67070</color>
    <color name="blue">#00B2FF</color>
Button(
    onClick = {}
    colors = ButtonDefaults.buttonColors(
        backgroundColor = Color(R.color.red)
    )
)
{
    Text(text = "Cancel")
}

but that results in:

enter image description here

and (as you can guess) isn't either the color nor the way I would like it to look like I've found other way to change the background color ("backgroundColor = Color(0xFFF67070)")

enter image description here

but this bit of code looks confusing, how can I change the background color of that button using resources?

thanks in advance :)

4

1 回答 1

1

You have to use the method colorResource

Button(
    onClick = {},
    colors = ButtonDefaults.buttonColors(
            backgroundColor = colorResource(id = R.color.red)
            )
)
{
    Text(text = "Cancel")
}

enter image description here

于 2021-08-30T16:42:55.503 回答