public static Paint parseColor(String valueStr){
  String c=valueStr.startsWith("#") ? valueStr.substring(1) : valueStr;
  if (c.length() != 6 && c.length() != 8) {
    throw new IllegalArgumentException("Invalid color specification: " + valueStr);
  }
  String r=c.substring(0,2), g=c.substring(2,4), b=c.substring(4,6);
  if (c.length() == 6) {
    return new Color(Integer.parseInt(r,16),Integer.parseInt(g,16),Integer.parseInt(b,16));
  }
 else {
    String a=c.substring(6);
    return new Color(Integer.parseInt(r,16),Integer.parseInt(g,16),Integer.parseInt(b,16),Integer.parseInt(a,16));
  }
}

public static Paint parseColor ( String valueStr ) { String c = valueStr . startsWith ( "#" ) ? valueStr . substring ( 1 ) : valueStr ; if ( c . length ( ) != 6 && c . length ( ) != 8 ) { throw new IllegalArgumentException ( "Invalid color specification: " + valueStr ) ; } String r = c . substring ( 0 , 2 ) , g = c . substring ( 2 , 4 ) , b = c . substring ( 4 , 6 ) ; if ( c . length ( ) == 6 ) { return new Color ( Integer . parseInt ( r , 16 ) , Integer . parseInt ( g , 16 ) , Integer . parseInt ( b , 16 ) ) ; } else { String a = c . substring ( 6 ) ; return new Color ( Integer . parseInt ( r , 16 ) , Integer . parseInt ( g , 16 ) , Integer . parseInt ( b , 16 ) , Integer . parseInt ( a , 16 ) ) ; } }
parses input string as color . the color string should be of the form # rrggbb ( no alpha specified , opaque color ) or # rrggbbaa ( alpa specified , transparent colors ) . leading character ' # ' is optional .
