How to convert a color integer to a hex String in Android?
I have an integer that was generated from an android.graphics.Color
The Integer has a value of -16776961
How do I convert this value into a hex string with the format #RRGGBB
Simply put: I would like to output #0000FF from -16776961
Note: I do not want the output to contain an alpha and i have also tried this example without any success
掩码确保你只能得到RRGGBB,并且%06X给你零填充十六进制(总是6个字符长):
String hexColor = String.format("#%06X", (0xFFFFFF & intColor));
Try Integer.toHexString()
Source: In Java, how do I convert a byte array to a string of hex digits while keeping leading zeros?
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.
链接地址: http://www.djcxy.com/p/87408.html上一篇: js减轻/变暗颜色