Dzięki tej metodzie Integer.toHexString można mieć Nieznany wyjątek kolorów dla niektórych kolorów, gdy przy użyciu Color.parseColor.
I z tej metody string.Format ("#% 06X" (0xFFFFFF & intColor)), stracisz wartość alfa.
Więc polecam tę metodę:
public static String ColorToHex(int color) {
int alpha = android.graphics.Color.alpha(color);
int blue = android.graphics.Color.blue(color);
int green = android.graphics.Color.green(color);
int red = android.graphics.Color.red(color);
String alphaHex = To00Hex(alpha);
String blueHex = To00Hex(blue);
String greenHex = To00Hex(green);
String redHex = To00Hex(red);
// hexBinary value: aabbggrr
StringBuilder str = new StringBuilder("#");
str.append(alphaHex);
str.append(blueHex);
str.append(greenHex);
str.append(redHex);
return str.toString();
}
private static String To00Hex(int value) {
String hex = "00".concat(Integer.toHexString(value));
return hex.substring(hex.length()-2, hex.length());
}
Jakie są próbujesz ustawić kolor hex? Myślę, że jest tu inna odpowiedź – Blundell
@Blundell Wysyłam kolor do zewnętrznej aplikacji. Kolor musi być w tym formacie #RRGGBB –
Co jest nie tak z http://developer.android.com/reference/android/content/res/Resources.html#getColor)? Będziesz musiał wkleić adres URL lub przewinąć do getColor (int) – Blundell