我想设置的值:红色:0.910绿色:0.969蓝色:0.996 alpha: 1.0
我得到color为:
int color=Color.argb(1.0,0.910,0.969,0.996)
但是这不起作用
我想得到十六进制颜色的值为#FF00FF。任何建议吗?
谢谢
使用它来获取十六进制值
protected int toHex(Color col) {
String as = pad(Integer.toHexString(col.getAlpha()));
String rs = pad(Integer.toHexString(col.getRed()));
String gs = pad(Integer.toHexString(col.getGreen()));
String bs = pad(Integer.toHexString(col.getBlue()));
String hex = "0x" + as + rs + gs + bs;
return Integer.parseInt(hex, 16);
}
private static final String pad(String s) {
return (s.length() == 1) ? "0" + s : s;
}
eg: int color = toHex(new color (1f, 1f, 1f, 1f));
这是我提到的链接将RGBA值转换为十六进制颜色代码
相关链接:
如何将颜色整数转换为十六进制字符串在Android?