public static Color decode(String hexColor, Color defaultColor) { Color color = getColor(hexColor, null); if (color==null) { if (hexColor.startsWith("#")) hexColor = hexColor.substring(1); int len = hexColor.length(); if (!(len==6 || len==8)) return defaultColor; float alpha = len==8?parseHex(hexColor.substring(0,2)):1f; if (len==8) hexColor = hexColor.substring(2); float red = parseHex(hexColor.substring(0,2)); float green = parseHex(hexColor.substring(2,4)); float blue = parseHex(hexColor.substring(4,6)); color = new Color(red, green, blue, alpha); } return color; }
public static Color decode(String hexColor, Color defaultColor) { Color color = getColor(hexColor, null); if (color==null) { if (hexColor.startsWith("#")) hexColor = hexColor.substring(1); int len = hexColor.length(); if (!(len==6 || len==8)) return defaultColor; float alpha = len==8?parseHex(hexColor.substring(0,2)):1f; if (len==8) hexColor = hexColor.substring(2); float red = parseHex(hexColor.substring(0,2)); float green = parseHex(hexColor.substring(2,4)); float blue = parseHex(hexColor.substring(4,6)); color = new Color(red, green, blue, alpha); } return color; }