you can try something like this.
/**
* @param rgbColor/argbColor This function take "rgb(123,23,23)/argb(123,12,12,12)" as input String and returns
* actual Color object for its equivalent rgb value
*/
public static int parseRgbColor(@NonNull String rgbColor) {
Pattern rgbColorPattern = Pattern.compile("rgb *\\( *([0-9]+), *([0-9]+), *([0-9]+) *\\)");
Pattern argbColorPattern = Pattern.compile("argb *\\( *([0-9]+), *([0-9]+), *([0-9]+), *([0-9]+) *\\)");
Matcher colorMatch = rgbColorPattern.matcher(rgbColor.toLowerCase());
if (colorMatch.matches()) {
return Color.rgb(Integer.valueOf(colorMatch.group(1)), Integer.valueOf(colorMatch.group(2)), Integer.valueOf(colorMatch.group(3)));
} else {
colorMatch = argbColorPattern.matcher(rgbColor.toLowerCase());
if (colorMatch.matches()) {
return Color.argb(Integer.valueOf(colorMatch.group(1)), Integer.valueOf(colorMatch.group(2)), Integer.valueOf(colorMatch.group(3)), Integer.valueOf(colorMatch.group(4)));
}
}
return -1;
}