https://kotlinlang.org logo
#compose
Title
# compose
d

Daniele B

09/28/2020, 8:39 PM
I am doing a multiplatform project, and I am defining the color pallette in the shared view model. Is there a simple function to convert the 6-char RGB string (e.g. “CC6699”) into a 
androidx.compose.ui.graphics.Color
 object ?
For the moment, I decided to write an extension function:
Copy code
fun String.toColor() : Color {
    return Color(("FF"+this).toLong(16))
}
d

dagomni

09/29/2020, 12:53 AM
You can define colors using Long, like this
Copy code
val pink = 0xFFE83E62
That way you can skip String to Long conversion