question: 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 ) ) ; } }
target:  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.