ColorKt
public final class ColorKt
Summary
Public methods |
|
|---|---|
static final float |
@RequiresApi(value = 26)Returns the first component of the color. |
static final int |
component1(@ColorInt int receiver)Return the alpha component of a color int. |
static final float |
@RequiresApi(value = 26)Returns the first component of the color. |
static final float |
@RequiresApi(value = 26)Returns the second component of the color. |
static final int |
component2(@ColorInt int receiver)Return the red component of a color int. |
static final float |
@RequiresApi(value = 26)Returns the second component of the color. |
static final float |
@RequiresApi(value = 26)Returns the third component of the color. |
static final int |
component3(@ColorInt int receiver)Return the green component of a color int. |
static final float |
@RequiresApi(value = 26)Returns the third component of the color. |
static final float |
@RequiresApi(value = 26)Returns the fourth component of the color. |
static final int |
component4(@ColorInt int receiver)Return the blue component of a color int. |
static final float |
@RequiresApi(value = 26)Returns the fourth component of the color. |
static final @NonNull Color |
@RequiresApi(value = 26)Converts the color receiver to a color in the specified color space. |
static final @NonNull Color |
@RequiresApi(value = 26)Converts the color receiver to a color in the specified color space. |
static final @ColorLong long |
@RequiresApi(value = 26)Converts the color int receiver to a color long in the specified color space. |
static final @ColorLong long |
@RequiresApi(value = 26)Converts the color int receiver to a color long in the specified color space. |
static final @ColorLong long |
@RequiresApi(value = 26)Converts the color long receiver to a color long in the specified color space. |
static final @ColorLong long |
@RequiresApi(value = 26)Converts the color long receiver to a color long in the specified color space. |
static final int |
Return the alpha component of a color int. |
static final float |
@RequiresApi(value = 26)Return the alpha component of a color long. |
static final int |
Return the blue component of a color int. |
static final float |
@RequiresApi(value = 26)Return the blue component of a color long. |
static final @NonNull ColorSpace |
@RequiresApi(value = 26)Returns the color space encoded in the specified color long. |
static final int |
Return the green component of a color int. |
static final float |
@RequiresApi(value = 26)Return the green component of a color long. |
static final float |
@RequiresApi(value = 26)Returns the relative luminance of a color int, assuming sRGB encoding. |
static final float |
@RequiresApi(value = 26)Returns the relative luminance of a color. |
static final int |
Return the red component of a color int. |
static final float |
@RequiresApi(value = 26)Return the red component of a color long. |
static final boolean |
@RequiresApi(value = 26)Indicates whether the color is in the |
static final boolean |
@RequiresApi(value = 26)Indicates whether the color is in a |
static final @NonNull Color |
Composites two translucent colors together. |
static final @NonNull Color |
@RequiresApi(value = 26)Creates a new |
static final @NonNull Color |
@RequiresApi(value = 26)Creates a new |
static final @ColorInt int |
@RequiresApi(value = 26)Converts the specified |
static final @ColorInt int |
toColorInt(@NonNull String receiver) |
static final @ColorLong long |
@RequiresApi(value = 26)Converts the specified ARGB |
Public methods
component1
@RequiresApi(value = 26)
public static final float component1(@NonNull Color receiver)
Returns the first component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the first component is "red".
This method allows to use destructuring declarations when working with colors, for example:
val (red, green, blue) = myColor
component1
public static final int component1(@ColorInt int receiver)
Return the alpha component of a color int. This is equivalent to calling:
Color.alpha(myInt)
This method allows to use destructuring declarations when working with colors, for example:
val (alpha, red, green, blue) = myColor
component1
@RequiresApi(value = 26)
public static final float component1(@ColorLong long receiver)
Returns the first component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the first component is "red".
This method allows to use destructuring declarations when working with colors, for example:
val (red, green, blue, alpha) = myColorLong
component2
@RequiresApi(value = 26)
public static final float component2(@NonNull Color receiver)
Returns the second component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the second component is "green".
This method allows to use destructuring declarations when working with colors, for example:
val (red, green, blue) = myColor
component2
public static final int component2(@ColorInt int receiver)
Return the red component of a color int. This is equivalent to calling:
Color.red(myInt)
This method allows to use destructuring declarations when working with colors, for example:
val (alpha, red, green, blue) = myColor
component2
@RequiresApi(value = 26)
public static final float component2(@ColorLong long receiver)
Returns the second component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the second component is "green".
This method allows to use destructuring declarations when working with colors, for example:
val (red, green, blue, alpha) = myColorLong
component3
@RequiresApi(value = 26)
public static final float component3(@NonNull Color receiver)
Returns the third component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the third component is "blue". = * This method allows to use destructuring declarations when working with colors, for example:
val (red, green, blue) = myColor
component3
public static final int component3(@ColorInt int receiver)
Return the green component of a color int. This is equivalent to calling:
Color.green(myInt)
This method allows to use destructuring declarations when working with colors, for example:
val (alpha, red, green, blue) = myColor
component3
@RequiresApi(value = 26)
public static final float component3(@ColorLong long receiver)
Returns the third component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the third component is "blue".
This method allows to use destructuring declarations when working with colors, for example:
val (red, green, blue, alpha) = myColorLong
component4
@RequiresApi(value = 26)
public static final float component4(@NonNull Color receiver)
Returns the fourth component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the fourth component is "alpha".
This method allows to use destructuring declarations when working with colors, for example:
val (red, green, blue, alpha) = myColor
component4
public static final int component4(@ColorInt int receiver)
Return the blue component of a color int. This is equivalent to calling:
Color.blue(myInt)
This method allows to use destructuring declarations when working with colors, for example:
val (alpha, red, green, blue) = myColor
component4
@RequiresApi(value = 26)
public static final float component4(@ColorLong long receiver)
Returns the fourth component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the fourth component is "alpha".
This method allows to use destructuring declarations when working with colors, for example:
val (red, green, blue, alpha) = myColorLong
convertTo
@RequiresApi(value = 26)
public static final @NonNull Color convertTo(@NonNull Color receiver, @NonNull ColorSpace colorSpace)
Converts the color receiver to a color in the specified color space. This is equivalent to calling:
myColor.convert(colorSpace)
convertTo
@RequiresApi(value = 26)
public static final @NonNull Color convertTo(@NonNull Color receiver, @NonNull ColorSpace.Named colorSpace)
Converts the color receiver to a color in the specified color space. This is equivalent to calling:
myColor.convert(ColorSpace.get(colorSpace))
convertTo
@RequiresApi(value = 26)
public static final @ColorLong long convertTo(@ColorInt int receiver, @NonNull ColorSpace colorSpace)
Converts the color int receiver to a color long in the specified color space. This is equivalent to calling:
Color.convert(myColorInt, colorSpace)
convertTo
@RequiresApi(value = 26)
public static final @ColorLong long convertTo(@ColorInt int receiver, @NonNull ColorSpace.Named colorSpace)
Converts the color int receiver to a color long in the specified color space. This is equivalent to calling:
Color.convert(myColorInt, ColorSpace.get(colorSpace))
convertTo
@RequiresApi(value = 26)
public static final @ColorLong long convertTo(@ColorLong long receiver, @NonNull ColorSpace colorSpace)
Converts the color long receiver to a color long in the specified color space. This is equivalent to calling:
Color.convert(myColorLong, colorSpace)
convertTo
@RequiresApi(value = 26)
public static final @ColorLong long convertTo(@ColorLong long receiver, @NonNull ColorSpace.Named colorSpace)
Converts the color long receiver to a color long in the specified color space. This is equivalent to calling:
Color.convert(myColorLong, ColorSpace.get(colorSpace))
getAlpha
public static final int getAlpha(@ColorInt int receiver)
Return the alpha component of a color int. This is equivalent to calling:
Color.alpha(myInt)
getAlpha
@RequiresApi(value = 26)
public static final float getAlpha(@ColorLong long receiver)
Return the alpha component of a color long. This is equivalent to calling:
Color.alpha(myLong)
getBlue
public static final int getBlue(@ColorInt int receiver)
Return the blue component of a color int. This is equivalent to calling:
Color.blue(myInt)
getBlue
@RequiresApi(value = 26)
public static final float getBlue(@ColorLong long receiver)
Return the blue component of a color long. This is equivalent to calling:
Color.blue(myLong)
getColorSpace
@RequiresApi(value = 26)
public static final @NonNull ColorSpace getColorSpace(@ColorLong long receiver)
Returns the color space encoded in the specified color long.
getGreen
public static final int getGreen(@ColorInt int receiver)
Return the green component of a color int. This is equivalent to calling:
Color.green(myInt)
getGreen
@RequiresApi(value = 26)
public static final float getGreen(@ColorLong long receiver)
Return the green component of a color long. This is equivalent to calling:
Color.green(myLong)
getLuminance
@RequiresApi(value = 26)
public static final float getLuminance(@ColorInt int receiver)
Returns the relative luminance of a color int, assuming sRGB encoding. Based on the formula for relative luminance defined in WCAG 2.0, W3C Recommendation 11 December 2008.
getLuminance
@RequiresApi(value = 26)
public static final float getLuminance(@ColorLong long receiver)
Returns the relative luminance of a color. Based on the formula for relative luminance defined in WCAG 2.0, W3C Recommendation 11 December 2008.
getRed
public static final int getRed(@ColorInt int receiver)
Return the red component of a color int. This is equivalent to calling:
Color.red(myInt)
getRed
@RequiresApi(value = 26)
public static final float getRed(@ColorLong long receiver)
Return the red component of a color long. This is equivalent to calling:
Color.red(myLong)
isSrgb
@RequiresApi(value = 26)
public static final boolean isSrgb(@ColorLong long receiver)
Indicates whether the color is in the sRGB color space.
isWideGamut
@RequiresApi(value = 26)
public static final boolean isWideGamut(@ColorLong long receiver)
Indicates whether the color is in a wide-gamut color space.
plus
@RequiresApi(value = 26)
public static final @NonNull Color plus(@NonNull Color receiver, @NonNull Color c)
Composites two translucent colors together. More specifically, adds two colors using the source over blending mode. The colors must not be pre-multiplied and the result is a non pre-multiplied color.
If the two colors have different color spaces, the color in the right-hand part of the expression is converted to the color space of the color in left-hand part of the expression.
The following example creates a purple color by blending opaque blue with semi-translucent red:
val purple = Color.valueOf(0f, 0f, 1f) + Color.valueOf(1f, 0f, 0f, 0.5f)
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if the |
toColor
@RequiresApi(value = 26)
public static final @NonNull Color toColor(@ColorInt int receiver)
Creates a new Color instance from a color int. The resulting color is in the sRGB color space.
toColor
@RequiresApi(value = 26)
public static final @NonNull Color toColor(@ColorLong long receiver)
Creates a new Color instance from a color long.
toColorInt
@RequiresApi(value = 26)
public static final @ColorInt int toColorInt(@ColorLong long receiver)
Converts the specified color long to an ARGB color int.
toColorInt
public static final @ColorInt int toColorInt(@NonNull String receiver)
Return a corresponding Int color of this String.
Supported formats are:
#RRGGBB
#AARRGGBB
The following names are also accepted: "red", "blue", "green", "black", "white", "gray", "cyan", "magenta", "yellow", "lightgray", "darkgray", "grey", "lightgrey", "darkgrey", "aqua", "fuchsia", "lime", "maroon", "navy", "olive", "purple", "silver", "teal".
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if this |
toColorLong
@RequiresApi(value = 26)
public static final @ColorLong long toColorLong(@ColorInt int receiver)
Converts the specified ARGB color int to an RGBA color long in the sRGB color space.