user10876921
user10876921

Reputation:

Android Hex color to Color

I am facing an Issue converting Hex color #000 to Color or RGB. Android Color.parseColor doesn't support shortened hex code.

Please suggest the best solution.

Upvotes: 0

Views: 253

Answers (1)

GTID
GTID

Reputation: 628

I think best way is

int red = colorString.charAt(1) == '0' ? 0 : 255;
int blue = colorString.charAt(2) == '0' ? 0 : 255;
int green = colorString.charAt(3) == '0' ? 0 : 255;
Color.rgb(red, green,blue);

Upvotes: 1

Related Questions