public static Color fromHex ( String hex ) { if ( hex . startsWith ( "#" ) ) { hex = hex . substring ( 1 ) ; } int length = hex . length ( ) ; int total = 6 ; if ( length < total ) { // we have a shortened version String token = hex ; int tokenLength = token . length ( ) ; for ( int i = 0 ; i < total ; i = i + tokenLength ) { hex += token ; } } int index = 0 ; String r = hex . substring ( index , index + 2 ) ; String g = hex . substring ( index + 2 , index + 4 ) ; String b = hex . substring ( index + 4 , index + total ) ; return new Color ( Integer . valueOf ( r , 16 ) , Integer . valueOf ( g , 16 ) , Integer . valueOf ( b , 16 ) ) ; }
Convert hex color to Color .