Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reuse colors in xml while defining Jetpack Compose Theme

I know that with Jetpack Compose I can define colors in Kotlin files. Since I'm migrating an app that used not to use Jetpack Compose, I'd like to keep pointing to the colors in the XML until I get rid of all the places when I'm already using them.

I know that I can use colorResource in a @Composable function but I can't do it when I define the palette in a Kotlin file.

Is it possible to do something equivalent to this?

private val DarkColorPalette = darkColors(
    primary = colorResource(id = R.color.company),
    ...
)
like image 344
kingston Avatar asked Feb 02 '26 03:02

kingston


1 Answers

The way I did it is by using @Composable functions even for the definitions of the colors:

@Composable
fun darkColorPalette() = darkColors(
    primary = colorResource(id = R.color.company),
)
like image 175
kingston Avatar answered Feb 03 '26 17:02

kingston



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!