java.lang.Object | |
↳ | sofia.graphics.Color |
Represents a color, which is composed of red, green, blue, and alpha
components, which are integers between 0 and 255. Color objects are
immutable – once one is created, it is not not possible to change its
color components. Methods like brighter()
and darker()
return a new color rather than modify the receiver.
Colors cannot be created using a constructor. Instead, there are a few static factory methods that you can call to obtain instances of this class. These methods let you get a color by:
fromRawColor(int)
, see
below)getRandomColor()
)gray(int)
, gray(int, int)
)hsv(float, float, float)
,
hsv(float, float, float, int)
)rgb(int, int, int)
,
rgb(int, int, int, int)
)
In traditional Android programming, colors are merely represented as plain
integers, and the android.graphics.Color class provides static
helper methods for manipulating those colors. This Color
class
treats colors as actual objects, with useful methods on the objects
themselves to manipulate them. If you need to pass a Color
object to
a traditional Android method that expects a color integer, use the
toRawColor()
method. Likewise, to create a Color
object
from an integer retrieved from a traditional Android API, use the
fromRawColor(int)
static factory method.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
public static final Color | aliceBlue | The named color "Alice blue" (HTML color code #F0F8FF). | |||||||||
public static final Color | antiqueWhite | The named color "Antique white" (HTML color code #FAEBD7). | |||||||||
public static final Color | aqua | The named color "Aqua" (HTML color code #00FFFF). | |||||||||
public static final Color | aquamarine | The named color "Aquamarine" (HTML color code #7FFFD4). | |||||||||
public static final Color | azure | The named color "Azure" (HTML color code #F0FFFF). | |||||||||
public static final Color | beige | The named color "Beige" (HTML color code #F5F5DC). | |||||||||
public static final Color | bisque | The named color "Bisque" (HTML color code #FFE4C4). | |||||||||
public static final Color | black | The named color "Black" (HTML color code #000000). | |||||||||
public static final Color | blanchedAlmond | The named color "Blanched almond" (HTML color code #FFEBCD). | |||||||||
public static final Color | blue | The named color "Blue" (HTML color code #0000FF). | |||||||||
public static final Color | blueViolet | The named color "Blue violet" (HTML color code #8A2BE2). | |||||||||
public static final Color | brown | The named color "Brown" (HTML color code #A52A2A). | |||||||||
public static final Color | burlyWood | The named color "Burly wood" (HTML color code #DEB887). | |||||||||
public static final Color | cadetBlue | The named color "Cadet blue" (HTML color code #5F9EA0). | |||||||||
public static final Color | chartreuse | The named color "Chartreuse" (HTML color code #7FFF00). | |||||||||
public static final Color | chocolate | The named color "Chocolate" (HTML color code #D2691E). | |||||||||
public static final Color | clear | A convenience value representing a clear/transparent color. | |||||||||
public static final Color | coral | The named color "Coral" (HTML color code #FF7F50). | |||||||||
public static final Color | cornflowerBlue | The named color "Cornflower blue" (HTML color code #6495ED). | |||||||||
public static final Color | cornsilk | The named color "Cornsilk" (HTML color code #FFF8DC). | |||||||||
public static final Color | crimson | The named color "Crimson" (HTML color code #DC143C). | |||||||||
public static final Color | cyan | The named color "Cyan" (HTML color code #00FFFF). | |||||||||
public static final Color | darkBlue | The named color "Dark blue" (HTML color code #00008B). | |||||||||
public static final Color | darkCyan | The named color "Dark cyan" (HTML color code #008B8B). | |||||||||
public static final Color | darkGoldenRod | The named color "Dark golden rod" (HTML color code #B8860B). | |||||||||
public static final Color | darkGray | The named color "Dark gray" (HTML color code #A9A9A9). | |||||||||
public static final Color | darkGreen | The named color "Dark green" (HTML color code #006400). | |||||||||
public static final Color | darkKhaki | The named color "Dark khaki" (HTML color code #BDB76B). | |||||||||
public static final Color | darkMagenta | The named color "Dark magenta" (HTML color code #8B008B). | |||||||||
public static final Color | darkOliveGreen | The named color "Dark olive green" (HTML color code #556B2F). | |||||||||
public static final Color | darkOrange | The named color "Dark orange" (HTML color code #FF8C00). | |||||||||
public static final Color | darkOrchid | The named color "Dark orchid" (HTML color code #9932CC). | |||||||||
public static final Color | darkRed | The named color "Dark red" (HTML color code #8B0000). | |||||||||
public static final Color | darkSalmon | The named color "Dark salmon" (HTML color code #E9967A). | |||||||||
public static final Color | darkSeaGreen | The named color "Dark sea green" (HTML color code #8FBC8F). | |||||||||
public static final Color | darkSlateBlue | The named color "Dark slate blue" (HTML color code #483D8B). | |||||||||
public static final Color | darkSlateGray | The named color "Dark slate gray" (HTML color code #2F4F4F). | |||||||||
public static final Color | darkTurquoise | The named color "Dark turquoise" (HTML color code #00CED1). | |||||||||
public static final Color | darkViolet | The named color "Dark violet" (HTML color code #9400D3). | |||||||||
public static final Color | deepPink | The named color "Deep pink" (HTML color code #FF1493). | |||||||||
public static final Color | deepSkyBlue | The named color "Deep sky blue" (HTML color code #00BFFF). | |||||||||
public static final Color | dimGray | The named color "Dim gray" (HTML color code #696969). | |||||||||
public static final Color | dodgerBlue | The named color "Dodger blue" (HTML color code #1E90FF). | |||||||||
public static final Color | fireBrick | The named color "Fire brick" (HTML color code #B22222). | |||||||||
public static final Color | floralWhite | The named color "Floral white" (HTML color code #FFFAF0). | |||||||||
public static final Color | forestGreen | The named color "Forest green" (HTML color code #228B22). | |||||||||
public static final Color | fuchsia | The named color "Fuchsia" (HTML color code #FF00FF). | |||||||||
public static final Color | gainsboro | The named color "Gainsboro" (HTML color code #DCDCDC). | |||||||||
public static final Color | ghostWhite | The named color "Ghost white" (HTML color code #F8F8FF). | |||||||||
public static final Color | gold | The named color "Gold" (HTML color code #FFD700). | |||||||||
public static final Color | goldenRod | The named color "Golden rod" (HTML color code #DAA520). | |||||||||
public static final Color | gray | The named color "Gray" (HTML color code #808080). | |||||||||
public static final Color | green | The named color "Green" (HTML color code #008000). | |||||||||
public static final Color | greenYellow | The named color "Green yellow" (HTML color code #ADFF2F). | |||||||||
public static final Color | honeyDew | The named color "Honey dew" (HTML color code #F0FFF0). | |||||||||
public static final Color | hotPink | The named color "Hot pink" (HTML color code #FF69B4). | |||||||||
public static final Color | indianRed | The named color "Indian red" (HTML color code #CD5C5C). | |||||||||
public static final Color | indigo | The named color "Indigo" (HTML color code #4B0082). | |||||||||
public static final Color | ivory | The named color "Ivory" (HTML color code #FFFFF0). | |||||||||
public static final Color | khaki | The named color "Khaki" (HTML color code #F0E68C). | |||||||||
public static final Color | lavender | The named color "Lavender" (HTML color code #E6E6FA). | |||||||||
public static final Color | lavenderBlush | The named color "Lavender blush" (HTML color code #FFF0F5). | |||||||||
public static final Color | lawnGreen | The named color "Lawn green" (HTML color code #7CFC00). | |||||||||
public static final Color | lemonChiffon | The named color "Lemon chiffon" (HTML color code #FFFACD). | |||||||||
public static final Color | lightBlue | The named color "Light blue" (HTML color code #ADD8E6). | |||||||||
public static final Color | lightCoral | The named color "Light coral" (HTML color code #F08080). | |||||||||
public static final Color | lightCyan | The named color "Light cyan" (HTML color code #E0FFFF). | |||||||||
public static final Color | lightGoldenRodYellow | The named color "Light golden rod yellow" (HTML color code #FAFAD2). | |||||||||
public static final Color | lightGray | The named color "Light gray" (HTML color code #D3D3D3). | |||||||||
public static final Color | lightGreen | The named color "Light green" (HTML color code #90EE90). | |||||||||
public static final Color | lightPink | The named color "Light pink" (HTML color code #FFB6C1). | |||||||||
public static final Color | lightSalmon | The named color "Light salmon" (HTML color code #FFA07A). | |||||||||
public static final Color | lightSeaGreen | The named color "Light sea green" (HTML color code #20B2AA). | |||||||||
public static final Color | lightSkyBlue | The named color "Light sky blue" (HTML color code #87CEFA). | |||||||||
public static final Color | lightSlateGray | The named color "Light slate gray" (HTML color code #778899). | |||||||||
public static final Color | lightSteelBlue | The named color "Light steel blue" (HTML color code #B0C4DE). | |||||||||
public static final Color | lightYellow | The named color "Light yellow" (HTML color code #FFFFE0). | |||||||||
public static final Color | lime | The named color "Lime" (HTML color code #00FF00). | |||||||||
public static final Color | limeGreen | The named color "Lime green" (HTML color code #32CD32). | |||||||||
public static final Color | linen | The named color "Linen" (HTML color code #FAF0E6). | |||||||||
public static final Color | magenta | The named color "Magenta" (HTML color code #FF00FF). | |||||||||
public static final Color | maroon | The named color "Maroon" (HTML color code #800000). | |||||||||
public static final Color | mediumAquamarine | The named color "Medium aquamarine" (HTML color code #66CDAA). | |||||||||
public static final Color | mediumBlue | The named color "Medium blue" (HTML color code #0000CD). | |||||||||
public static final Color | mediumOrchid | The named color "Medium orchid" (HTML color code #BA55D3). | |||||||||
public static final Color | mediumPurple | The named color "Medium purple" (HTML color code #9370D8). | |||||||||
public static final Color | mediumSeaGreen | The named color "Medium sea green" (HTML color code #3CB371). | |||||||||
public static final Color | mediumSlateBlue | The named color "Medium slate blue" (HTML color code #7B68EE). | |||||||||
public static final Color | mediumSpringGreen | The named color "Medium spring green" (HTML color code #00FA9A). | |||||||||
public static final Color | mediumTurquoise | The named color "Medium turquoise" (HTML color code #48D1CC). | |||||||||
public static final Color | mediumVioletRed | The named color "Medium violet red" (HTML color code #C71585). | |||||||||
public static final Color | midnightBlue | The named color "Midnight blue" (HTML color code #191970). | |||||||||
public static final Color | mintCream | The named color "Mint cream" (HTML color code #F5FFFA). | |||||||||
public static final Color | mistyRose | The named color "Misty rose" (HTML color code #FFE4E1). | |||||||||
public static final Color | moccasin | The named color "Moccasin" (HTML color code #FFE4B5). | |||||||||
public static final Color | navajoWhite | The named color "Navajo white" (HTML color code #FFDEAD). | |||||||||
public static final Color | navy | The named color "Navy" (HTML color code #000080). | |||||||||
public static final Color | oldLace | The named color "Old lace" (HTML color code #FDF5E6). | |||||||||
public static final Color | olive | The named color "Olive" (HTML color code #808000). | |||||||||
public static final Color | oliveDrab | The named color "Olive drab" (HTML color code #6B8E23). | |||||||||
public static final Color | orange | The named color "Orange" (HTML color code #FFA500). | |||||||||
public static final Color | orangeRed | The named color "Orange red" (HTML color code #FF4500). | |||||||||
public static final Color | orchid | The named color "Orchid" (HTML color code #DA70D6). | |||||||||
public static final Color | paleGoldenRod | The named color "Pale golden rod" (HTML color code #EEE8AA). | |||||||||
public static final Color | paleGreen | The named color "Pale green" (HTML color code #98FB98). | |||||||||
public static final Color | paleTurquoise | The named color "Pale turquoise" (HTML color code #AFEEEE). | |||||||||
public static final Color | paleVioletRed | The named color "Pale violet red" (HTML color code #D87093). | |||||||||
public static final Color | papayaWhip | The named color "Papaya whip" (HTML color code #FFEFD5). | |||||||||
public static final Color | peachPuff | The named color "Peach puff" (HTML color code #FFDAB9). | |||||||||
public static final Color | peru | The named color "Peru" (HTML color code #CD853F). | |||||||||
public static final Color | pink | The named color "Pink" (HTML color code #FFC0CB). | |||||||||
public static final Color | plum | The named color "Plum" (HTML color code #DDA0DD). | |||||||||
public static final Color | powderBlue | The named color "Powder blue" (HTML color code #B0E0E6). | |||||||||
public static final Color | purple | The named color "Purple" (HTML color code #800080). | |||||||||
public static final Color | red | The named color "Red" (HTML color code #FF0000). | |||||||||
public static final Color | rosyBrown | The named color "Rosy brown" (HTML color code #BC8F8F). | |||||||||
public static final Color | royalBlue | The named color "Royal blue" (HTML color code #4169E1). | |||||||||
public static final Color | saddleBrown | The named color "Saddle brown" (HTML color code #8B4513). | |||||||||
public static final Color | salmon | The named color "Salmon" (HTML color code #FA8072). | |||||||||
public static final Color | sandyBrown | The named color "Sandy brown" (HTML color code #F4A460). | |||||||||
public static final Color | seaGreen | The named color "Sea green" (HTML color code #2E8B57). | |||||||||
public static final Color | seaShell | The named color "Sea shell" (HTML color code #FFF5EE). | |||||||||
public static final Color | sienna | The named color "Sienna" (HTML color code #A0522D). | |||||||||
public static final Color | silver | The named color "Silver" (HTML color code #C0C0C0). | |||||||||
public static final Color | skyBlue | The named color "Sky blue" (HTML color code #87CEEB). | |||||||||
public static final Color | slateBlue | The named color "Slate blue" (HTML color code #6A5ACD). | |||||||||
public static final Color | slateGray | The named color "Slate gray" (HTML color code #708090). | |||||||||
public static final Color | snow | The named color "Snow" (HTML color code #FFFAFA). | |||||||||
public static final Color | springGreen | The named color "Spring green" (HTML color code #00FF7F). | |||||||||
public static final Color | steelBlue | The named color "Steel blue" (HTML color code #4682B4). | |||||||||
public static final Color | tan | The named color "Tan" (HTML color code #D2B48C). | |||||||||
public static final Color | teal | The named color "Teal" (HTML color code #008080). | |||||||||
public static final Color | thistle | The named color "Thistle" (HTML color code #D8BFD8). | |||||||||
public static final Color | tomato | The named color "Tomato" (HTML color code #FF6347). | |||||||||
public static final Color | turquoise | The named color "Turquoise" (HTML color code #40E0D0). | |||||||||
public static final Color | violet | The named color "Violet" (HTML color code #EE82EE). | |||||||||
public static final Color | wheat | The named color "Wheat" (HTML color code #F5DEB3). | |||||||||
public static final Color | white | The named color "White" (HTML color code #FFFFFF). | |||||||||
public static final Color | whiteSmoke | The named color "White smoke" (HTML color code #F5F5F5). | |||||||||
public static final Color | yellow | The named color "Yellow" (HTML color code #FFFF00). | |||||||||
public static final Color | yellowGreen | The named color "Yellow green" (HTML color code #9ACD32). |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int |
alpha()
Gets the alpha component of the receiver.
| ||||||||||
int |
blue()
Gets the blue component of the receiver.
| ||||||||||
Color |
brighter()
Gets a new
Color that is a brighter version of the receiver. | ||||||||||
Color |
darker()
Gets a new
Color that is a darker version of the receiver. | ||||||||||
boolean |
equals(Object other)
Gets a value indicating whether the receiving
Color is equal to
the specified object. | ||||||||||
static Color |
fromRawColor(int rawColor)
Gets a
Color that represents an Android color integer. | ||||||||||
static Color |
getRandomColor()
Gets the random color.
| ||||||||||
static Color |
gray(int gray)
Gets a
Color that represents a gray level, where a gray level of
0 is black and a gray level of 255 is white. | ||||||||||
static Color |
gray(int gray, int alpha)
Gets a
Color that represents a gray level with the specified
alpha, where a gray level of 0 is black and a gray level of 255 is
white. | ||||||||||
int |
green()
Gets the green component of the receiver.
| ||||||||||
int |
hashCode()
Returns a hash code value for the object.
| ||||||||||
static Color |
hsv(float hue, float saturation, float value, int alpha)
Gets a
Color that is composed of the specified hue, saturation,
value, and alpha components. | ||||||||||
static Color |
hsv(float hue, float saturation, float value)
Gets a
Color that is composed of the specified hue, saturation,
and value components. | ||||||||||
float |
hue()
Gets the hue component of the receiver in the HSV color model.
| ||||||||||
boolean |
isOpaque()
Returns true if this color is opaque (it has an alpha of 255), or false if it has an alpha less than 255. | ||||||||||
boolean |
isTransparent()
Returns true if this color is transparent (it has an alpha of 0), or false if it has an alpha greater than 0. | ||||||||||
int |
red()
Gets the red component of the receiver.
| ||||||||||
static Color |
rgb(int red, int green, int blue)
Gets a
Color that is composed of the specified red, green, and
blue components. | ||||||||||
static Color |
rgb(int red, int green, int blue, int alpha)
Gets a
Color that is composed of the specified red, green, blue,
and alpha components. | ||||||||||
float |
saturation()
Gets the saturation component of the receiver in the HSV color model.
| ||||||||||
int |
toRawColor()
Gets the Android color integer that corresponds to the receiver.
| ||||||||||
String |
toString()
Gets a human-readable string representation of the color, in the format
"Color([red], [green], [blue], [alpha])".
| ||||||||||
float |
value()
Gets the value component of the receiver in the HSV color model.
| ||||||||||
Color |
withAlpha(int alpha)
Gets a new
Color that is chromatically the same as the receiver
(it has the same red, green, and blue components), but with a different
alpha component. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Gets the alpha component of the receiver.
Gets the blue component of the receiver.
Gets a new Color
that is a brighter version of the receiver. The
alpha value will remain the same.
Color
that is a brighter version of the receiver
Gets a new Color
that is a darker version of the receiver. The
alpha value will remain the same.
Color
that is a darker version of the receiver
Gets a value indicating whether the receiving Color
is equal to
the specified object. A Color
is equal to another object if the
other object is not null, a Color
, and has identical red, green,
blue, and alpha components as the receiver.
other | the other object |
---|
Gets a Color
that represents an Android color integer.
rawColor | the Android color integer |
---|
Color
that represents the specified Android color
integer
Gets a Color
that represents a gray level, where a gray level of
0 is black and a gray level of 255 is white. Pure gray levels have red,
green, and blue components that are all equal.
gray | the gray level, between 0 and 255 |
---|
Color
that represents the gray level
Gets a Color
that represents a gray level with the specified
alpha, where a gray level of 0 is black and a gray level of 255 is
white. Pure gray levels have red, green, and blue components that are
all equal.
gray | the gray level, between 0 and 255 |
---|---|
alpha | the alpha level, between 0 and 255 |
Color
that represents the gray level
Gets the green component of the receiver.
Returns a hash code value for the object.
Gets a Color
that is composed of the specified hue, saturation,
value, and alpha components.
hue | the hue component, between 0 (inclusive) and 360 (exclusive) |
---|---|
saturation | the saturation component, between 0 and 1 |
value | the value component, between 0 and 1 |
alpha | the alpha component, between 0 and 255 |
Color
composed of the specified hue, saturation,
value, and alpha components
Gets a Color
that is composed of the specified hue, saturation,
and value components.
hue | the hue component, between 0 (inclusive) and 360 (exclusive) |
---|---|
saturation | the saturation component, between 0 and 1 |
value | the value component, between 0 and 1 |
Color
composed of the specified hue, saturation, and
value components
Gets the hue component of the receiver in the HSV color model.
Returns true if this color is opaque (it has an alpha of 255), or false if it has an alpha less than 255.
Notice that isOpaque()
is not the strict opposite of
isTransparent()
. Colors with alpha between 1 and 254 will
return false for both.
Returns true if this color is transparent (it has an alpha of 0), or false if it has an alpha greater than 0.
Notice that isTransparent()
is not the strict opposite of
isOpaque()
. Colors with alpha between 1 and 254 will return
false for both.
Gets the red component of the receiver.
Gets a Color
that is composed of the specified red, green, and
blue components.
red | the red component, between 0 and 255 |
---|---|
green | the green component, between 0 and 255 |
blue | the blue component, between 0 and 255 |
Color
composed of the specified red, green, and blue
components
Gets a Color
that is composed of the specified red, green, blue,
and alpha components.
red | the red component, between 0 and 255 |
---|---|
green | the green component, between 0 and 255 |
blue | the blue component, between 0 and 255 |
alpha | the alpha component, between 0 and 255 |
Color
composed of the specified red, green, blue, and
alpha components
Gets the saturation component of the receiver in the HSV color model.
Gets the Android color integer that corresponds to the receiver.
Gets a human-readable string representation of the color, in the format "Color([red], [green], [blue], [alpha])".
Gets the value component of the receiver in the HSV color model.
Gets a new Color
that is chromatically the same as the receiver
(it has the same red, green, and blue components), but with a different
alpha component.
alpha | the desired alpha component of the new color |
---|
Color
that is chromatically the same as the receiver
but with a different alpha component