setting button background color bug?

194 views Asked by At

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 :)

1

There are 1 answers

0
Gabriele Mariotti On BEST ANSWER

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