d

    Daniele B

    1 year ago
    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:
    fun String.toColor() : Color {
        return Color(("FF"+this).toLong(16))
    }
    d

    dagomni

    1 year ago
    You can define colors using Long, like this
    val pink = 0xFFE83E62
    That way you can skip String to Long conversion