Creates an RGB color specified with an HTML or CSS attribute string.
This method supports the following formats:
"0x"
or "#"
and can either be 2 digits in the range 00
to 0xFF
or a
single digit in the range 0
to F
.
rgb(r,g,b)
or rgba(r,g,b,a)
format string.
Each of the r
, g
, or b
values can be an integer
from 0 to 255 or a floating point percentage value from 0.0 to 100.0
followed by the percent ( %
) character.
The alpha component, if present, is a
floating point value from 0.0 to 1.0. Spaces are allowed before or
after the numbers and between the percentage number and its percent
sign ( %
).
hsl(h,s,l)
or hsla(h,s,l,a)
format string.
The h
value is a floating point number from 0.0 to 360.0
representing the hue angle on a color wheel in degrees with
0.0
or 360.0
representing red, 120.0
representing green, and 240.0
representing blue. The
s
value is the saturation of the desired color represented
as a floating point percentage from gray ( 0.0
) to
the fully saturated color ( 100.0
) and the l
value
is the desired lightness or brightness of the desired color represented
as a floating point percentage from black ( 0.0
) to the full
brightness of the color ( 100.0
).
The alpha component, if present, is a floating
point value from 0.0 to 1.0. Spaces are allowed before or
after the numbers and between the percentage number and its percent
sign ( %
).
Examples:
Web Format String | Equivalent constant or factory call |
---|---|
Color.web("orange"); |
Color.ORANGE |
Color.web("0xff668840"); |
Color.rgb(255, 102, 136, 0.25) |
Color.web("0xff6688"); |
Color.rgb(255, 102, 136, 1.0) |
Color.web("#ff6688"); |
Color.rgb(255, 102, 136, 1.0) |
Color.web("#f68"); |
Color.rgb(255, 102, 136, 1.0) |
Color.web("rgb(255,102,136)"); |
Color.rgb(255, 102, 136, 1.0) |
Color.web("rgb(100%,50%,50%)"); |
Color.rgb(255, 128, 128, 1.0) |
Color.web("rgb(255,50%,50%,0.25)"); |
Color.rgb(255, 128, 128, 0.25) |
Color.web("hsl(240,100%,100%)"); |
Color.hsb(240.0, 1.0, 1.0, 1.0) |
Color.web("hsla(120,0%,0%,0.25)");
|
Color.hsb(120.0, 0.0, 0.0, 0.25)
|
colorString | the name or numeric representation of the color in one of the supported formats |
NullPointerException | if colorString is null | |
IllegalArgumentException | if colorString specifies
an unsupported color name or contains an illegal numeric value |
Diagram: Paint