How to create an Android Color from a hexadecimal/HTML string (#fff)

Android FAQ: How can I create a Color from a hexadecimal color string in Android?

The Android Color.parseColor method

Solution: Use the Android Color.parseColor method, like this:

int color = Color.parseColor("#519c3f");

I just used it like this in my code, where I directly set the Paint color:


The string shown is a hexadecimal/HTML color string which represents a light shade of green. The important part of this is that I liked that color in a prototype, then got the HTML/hexadecimal color string using Gimp, and then could use that string directly in my Android/Java application to create a color, without having to manually convert the color string to RGB.

Using an alpha value with Color.parseColor

To add an alpha value, just add two more hex values at the front of the string. This alpha setting (FF) means the color is “fully on,” i.e., it is not transparent at all:


This alpha setting (22) means the color is almost fully transparent:


Standard Android colors (Color class docs)

For the record, the full package for the Android Color class is Also, those docs state:

Supported formats are: #RRGGBB #AARRGGBB or 
one of the following names:

Creating Android colors using RGB values

Also, while I’m in the neighborhood, this is one way to create an Android Color instance using RGB values:

g.setColor(Color.rgb(130, 130, 130));