Convert hex color value ( #ffffff ) to integer value Convert hex color value ( #ffffff ) to integer value android android

Convert hex color value ( #ffffff ) to integer value


The real answer is to use:

Color.parseColor(myPassedColor) in Android, myPassedColor being the hex value like #000 or #000000 or #00000000.

However, this function does not support shorthand hex values such as #000.


Answer is really simple guys, in android if you want to convert hex color in to int, just use android Color class, example shown as below

this is for light gray color

Color.parseColor("#a8a8a8");

Thats it and you will get your result.


Integer.parseInt(myString.replaceFirst("#", ""), 16)