androidcolorshex

How to get a Color from hexadecimal Color String


I'd like to use a color from an hexa string such as "#FFFF0000" to (say) change the background color of a Layout. Color.HSVToColor looks like a winner but it takes a float[] as a parameter.

Am I any close to the solution at all?


Solution

  • Try Color class method:

    public static int parseColor (String colorString)
    

    From Android documentation:

    Supported formats are: #RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray'

    AndroidX: String.toColorInt()