to top
Android APIs
public class

Color

extends Object
java.lang.Object
   ↳ android.graphics.Color

Class Overview

The Color class defines methods for creating and converting color ints. Colors are represented as packed ints, made up of 4 bytes: alpha, red, green, blue. The values are unpremultiplied, meaning any transparency is stored solely in the alpha component, and not in the color components. The components are stored as follows (alpha << 24) | (red << 16) | (green << 8) | blue. Each component ranges between 0..255 with 0 meaning no contribution for that component, and 255 meaning 100% contribution. Thus opaque-black would be 0xFF000000 (100% opaque but no contributions from red, green, or blue), and opaque-white would be 0xFFFFFFFF

Summary

Constants
int BLACK
int BLUE
int CYAN
int DKGRAY
int GRAY
int GREEN
int LTGRAY
int MAGENTA
int RED
int TRANSPARENT
int WHITE
int YELLOW
Public Constructors
Color()
Public Methods
static int HSVToColor(float[] hsv)
Convert HSV components to an ARGB color.
static int HSVToColor(int alpha, float[] hsv)
Convert HSV components to an ARGB color.
static void RGBToHSV(int red, int green, int blue, float[] hsv)
Convert RGB components to HSV.
static int alpha(int color)
Return the alpha component of a color int.
static int argb(int alpha, int red, int green, int blue)
Return a color-int from alpha, red, green, blue components.
static int blue(int color)
Return the blue component of a color int.
static void colorToHSV(int color, float[] hsv)
Convert the argb color to its HSV components.
static int green(int color)
Return the green component of a color int.
static int parseColor(String colorString)
Parse the color string, and return the corresponding color-int.
static int red(int color)
Return the red component of a color int.
static int rgb(int red, int green, int blue)
Return a color-int from red, green, blue components.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int BLACK

Added in API level 1

Constant Value: -16777216 (0xff000000)

public static final int BLUE

Added in API level 1

Constant Value: -16776961 (0xff0000ff)

public static final int CYAN

Added in API level 1

Constant Value: -16711681 (0xff00ffff)

public static final int DKGRAY

Added in API level 1

Constant Value: -12303292 (0xff444444)

public static final int GRAY

Added in API level 1

Constant Value: -7829368 (0xff888888)

public static final int GREEN

Added in API level 1

Constant Value: -16711936 (0xff00ff00)

public static final int LTGRAY

Added in API level 1

Constant Value: -3355444 (0xffcccccc)

public static final int MAGENTA

Added in API level 1

Constant Value: -65281 (0xffff00ff)

public static final int RED

Added in API level 1

Constant Value: -65536 (0xffff0000)

public static final int TRANSPARENT

Added in API level 1

Constant Value: 0 (0x00000000)

public static final int WHITE

Added in API level 1

Constant Value: -1 (0xffffffff)

public static final int YELLOW

Added in API level 1

Constant Value: -256 (0xffffff00)

Public Constructors

public Color ()

Added in API level 1

Public Methods

public static int HSVToColor (float[] hsv)

Added in API level 1

Convert HSV components to an ARGB color. Alpha set to 0xFF. hsv[0] is Hue [0 .. 360) hsv[1] is Saturation [0...1] hsv[2] is Value [0...1] If hsv values are out of range, they are pinned.

Parameters
hsv 3 element array which holds the input HSV components.
Returns
  • the resulting argb color

public static int HSVToColor (int alpha, float[] hsv)

Added in API level 1

Convert HSV components to an ARGB color. The alpha component is passed through unchanged. hsv[0] is Hue [0 .. 360) hsv[1] is Saturation [0...1] hsv[2] is Value [0...1] If hsv values are out of range, they are pinned.

Parameters
alpha the alpha component of the returned argb color.
hsv 3 element array which holds the input HSV components.
Returns
  • the resulting argb color

public static void RGBToHSV (int red, int green, int blue, float[] hsv)

Added in API level 1

Convert RGB components to HSV. hsv[0] is Hue [0 .. 360) hsv[1] is Saturation [0...1] hsv[2] is Value [0...1]

Parameters
red red component value [0..255]
green green component value [0..255]
blue blue component value [0..255]
hsv 3 element array which holds the resulting HSV components.

public static int alpha (int color)

Added in API level 1

Return the alpha component of a color int. This is the same as saying color >>> 24

public static int argb (int alpha, int red, int green, int blue)

Added in API level 1

Return a color-int from alpha, red, green, blue components. These component values should be [0..255], but there is no range check performed, so if they are out of range, the returned color is undefined.

Parameters
alpha Alpha component [0..255] of the color
red Red component [0..255] of the color
green Green component [0..255] of the color
blue Blue component [0..255] of the color

public static int blue (int color)

Added in API level 1

Return the blue component of a color int. This is the same as saying color & 0xFF

public static void colorToHSV (int color, float[] hsv)

Added in API level 1

Convert the argb color to its HSV components. hsv[0] is Hue [0 .. 360) hsv[1] is Saturation [0...1] hsv[2] is Value [0...1]

Parameters
color the argb color to convert. The alpha component is ignored.
hsv 3 element array which holds the resulting HSV components.

public static int green (int color)

Added in API level 1

Return the green component of a color int. This is the same as saying (color >> 8) & 0xFF

public static int parseColor (String colorString)

Added in API level 1

Parse the color string, and return the corresponding color-int. If the string cannot be parsed, throws an IllegalArgumentException exception. Supported formats are: #RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray', 'grey', 'lightgrey', 'darkgrey', 'aqua', 'fuschia', 'lime', 'maroon', 'navy', 'olive', 'purple', 'silver', 'teal'

public static int red (int color)

Added in API level 1

Return the red component of a color int. This is the same as saying (color >> 16) & 0xFF

public static int rgb (int red, int green, int blue)

Added in API level 1

Return a color-int from red, green, blue components. The alpha component is implicity 255 (fully opaque). These component values should be [0..255], but there is no range check performed, so if they are out of range, the returned color is undefined.

Parameters
red Red component [0..255] of the color
green Green component [0..255] of the color
blue Blue component [0..255] of the color