Search code examples
androidandroid-jetpackandroid-jetpack-compose

How do I use Color resource directly in Jetpack Compose?


I want to use custom colors defined in the colors.xml class directly without using the Material theme colors or the default theme provided by the Jetpack. Is there any straightforward way to do it?


Solution

  • You can use colorResource() which loads a color resource.

    Text(
        text = "Hello World",
        color = colorResource(R.color.purple_200)
    )