JustSightseeing
JustSightseeing

Reputation: 3015

setting button background color bug?

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

Upvotes: 0

Views: 214

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363737

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

Upvotes: 1

Related Questions