How to get a Color from hexadecimal Color String
I'd like to use a color from an hexa string such as "#FFFF0000"
to (say) change the background color of a Layout. Color.HSVToColor
looks like a winner but it takes a float[]
as a parameter.
Am I any close to the solution at all?
Try Color
class method:
public static int parseColor (String colorString)
From Android documentation:
Supported formats are: #RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray'
尝试:
myLayout.setBackgroundColor(Color.parseColor("#636161"));
Convert that string to an int
color which can be used in setBackgroundColor
and setTextColor
String string = "#FFFF0000";
int color = Integer.parseInt(string.replaceFirst("^#",""), 16);
The 16 means it is hexadecimal and not your regular 0-9. The result should be the same as
int color = 0xFFFF0000;
链接地址: http://www.djcxy.com/p/87060.html
下一篇: 如何从十六进制颜色字符串中获取颜色