/**
* 加载rgba格式颜色
* 注意格式是 rgba(7, 66, 244, 0.64)
*
* @param rgba
*/
public static int getColorRgba(String rgba){
String substring = rgba.substring(5, rgba.length()-1);
String[] split = substring.split(",");
int argb = 0;
try {
int red = Integer.parseInt(split[0].trim());
int green = Integer.parseInt(split[1].trim());
int blue = Integer.parseInt(split[2].trim());
float alphaF = Float.parseFloat(split[3].trim());
if (0 <= red && red <= 255 &&
0 <= green && green <= 255 &&
0 <= blue && blue <= 255 &&
0f <= alphaF && alphaF <= 1f) {
return Color.argb((int) (alphaF * 255), red, green, blue);
}
} catch (NumberFormatException ignored) {
}
return argb;
}
android 加载rgba格式颜色
最新推荐文章于 2022-06-09 17:35:56 发布