Here you can find the source of rgbaToHex(String color)
public static String rgbaToHex(String color)
//package com.java2s; //License from project: Apache License public class Main { public static String rgbaToHex(String color) { if (isHexColor(color)) { return color; }/*from w ww .jav a2s.c o m*/ String f = color.substring("rgba(".length()); int l = f.lastIndexOf(","); if (l == -1) { return color; } String t = f.substring(0, l); String[] rgb = t.split(","); int r = Integer.parseInt(rgb[0], 10); int g = Integer.parseInt(rgb[1], 10); int b = Integer.parseInt(rgb[2], 10); //LogUtils.log(r+","+g+","+b); String rColor = Integer.toHexString(r); if (rColor.length() < 2) { rColor = "0" + r; } String gColor = Integer.toHexString(g); if (gColor.length() < 2) { gColor = "0" + g; } String bColor = Integer.toHexString(b); if (bColor.length() < 2) { bColor = "0" + b; } return "#" + rColor + gColor + bColor; } public static boolean isHexColor(String text) { if (!text.startsWith("#")) { return false; } if (text.length() != 4 && text.length() != 7) { return false; } return true; } }