Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android convert color int to hexa String

Tags:

android

colors

public static int RGB(float[] hsv) {     return Color.HSVToColor(hsv); } 

this function add an int, froma color. how can i convert that int to a hexa string: #efefef

like image 483
lacas Avatar asked Dec 22 '10 06:12

lacas


1 Answers

The answer of st0le is not correct with respect to colors. It does not work if first color components are 0. So toHexString is useless.

However this code will work as expected:

String strColor = String.format("#%06X", 0xFFFFFF & intColor); 
like image 145
Dmitry Kochin Avatar answered Oct 09 '22 09:10

Dmitry Kochin