How to convert a color integer to a hex String in Android? How to convert a color integer to a hex String in Android? java java

How to convert a color integer to a hex String in Android?


The mask makes sure you only get RRGGBB, and the %06X gives you zero-padded hex (always 6 chars long):

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


I believe i have found the answer, This code converts the integer to a hex string an removes the alpha.

Integer intColor = -16895234;String hexColor = "#" + Integer.toHexString(intColor).substring(2);

Note only use this code if you are sure that removing the alpha would not affect anything.