-2

I am working with hybrid android application where i need to pass color code from java class to html. My HTML code is expecting "#RGB", where as in my android code declared some color as Color.WHITE and Color.TRANSPARENT whose equivalent int values are -1 and 0

How can i convert Color.WHITE i.e (-1) to some #FFFFFF?

I know Color.parseColor(#FFFFFF) but i need reverse one.

Ganesh K
  • 2,623
  • 9
  • 51
  • 78
  • 1
    Already asked before more than once. http://stackoverflow.com/questions/6539879/how-to-convert-a-color-integer-to-a-hex-string-in-android – zsolt.kocsi Feb 13 '15 at 12:46

2 Answers2

1

Since color is actually an integer, you can easily convert it to hexadecimal with String.format. It seems you want to ignore the alpha channel so you can filter it out:

String.format("#%06X", color & 0xffffff);
StenSoft
  • 9,369
  • 25
  • 30
1

You could try this out

String hexColor = String.format("#%06X", (0xFFFFFF & intColor));

Reference here

Community
  • 1
  • 1
Marcus
  • 6,697
  • 11
  • 46
  • 89