MaterialColors
public
class
MaterialColors
extends Object
java.lang.Object | |
↳ | com.google.android.material.color.MaterialColors |
A utility class for common color variants used in Material themes.
Summary
Constants | |
---|---|
float |
ALPHA_DISABLED
|
float |
ALPHA_DISABLED_LOW
|
float |
ALPHA_FULL
|
float |
ALPHA_LOW
|
float |
ALPHA_MEDIUM
|
Public methods | |
---|---|
static
int
|
compositeARGBWithAlpha(int originalARGB, int alpha)
Calculates a new color by multiplying an additional alpha int value to the alpha channel of a color in integer type. |
static
int
|
getColor(Context context, int colorAttributeResId, int defaultValue)
Returns the color int for the provided theme color attribute, or the default value if the attribute is not set in the current theme. |
static
int
|
getColor(View view, int colorAttributeResId, int defaultValue)
Returns the color int for the provided theme color attribute, or the default value if the
attribute is not set in the current theme, using the |
static
int
|
getColor(Context context, int colorAttributeResId, String errorMessageComponent)
Returns the color int for the provided theme color attribute. |
static
int
|
getColor(View view, int colorAttributeResId)
Returns the color int for the provided theme color attribute, using the |
static
int
|
layer(View view, int backgroundColorAttributeResId, int overlayColorAttributeResId, float overlayAlpha)
Convenience method that wraps |
static
int
|
layer(int backgroundColor, int overlayColor)
Calculates a color that represents the layering of the |
static
int
|
layer(View view, int backgroundColorAttributeResId, int overlayColorAttributeResId)
Convenience method that calculates |
static
int
|
layer(int backgroundColor, int overlayColor, float overlayAlpha)
Calculates a color that represents the layering of the |
Inherited methods | |
---|---|
Constants
ALPHA_DISABLED
public static final float ALPHA_DISABLED
Constant Value: 0.38
ALPHA_DISABLED_LOW
public static final float ALPHA_DISABLED_LOW
Constant Value: 0.12
ALPHA_FULL
public static final float ALPHA_FULL
Constant Value: 1.0
ALPHA_LOW
public static final float ALPHA_LOW
Constant Value: 0.32
ALPHA_MEDIUM
public static final float ALPHA_MEDIUM
Constant Value: 0.54
Public methods
compositeARGBWithAlpha
public static int compositeARGBWithAlpha (int originalARGB, int alpha)
Calculates a new color by multiplying an additional alpha int value to the alpha channel of a color in integer type.
Parameters | |
---|---|
originalARGB |
int : The original color. |
alpha |
int : The additional alpha [0-255]. |
Returns | |
---|---|
int |
The blended color. |
getColor
public static int getColor (Context context, int colorAttributeResId, int defaultValue)
Returns the color int for the provided theme color attribute, or the default value if the attribute is not set in the current theme.
Parameters | |
---|---|
context |
Context |
colorAttributeResId |
int |
defaultValue |
int |
Returns | |
---|---|
int |
getColor
public static int getColor (View view, int colorAttributeResId, int defaultValue)
Returns the color int for the provided theme color attribute, or the default value if the
attribute is not set in the current theme, using the view
's Context
.
Parameters | |
---|---|
view |
View |
colorAttributeResId |
int |
defaultValue |
int |
Returns | |
---|---|
int |
getColor
public static int getColor (Context context, int colorAttributeResId, String errorMessageComponent)
Returns the color int for the provided theme color attribute.
Parameters | |
---|---|
context |
Context |
colorAttributeResId |
int |
errorMessageComponent |
String |
Returns | |
---|---|
int |
Throws | |
---|---|
IllegalArgumentException |
if the attribute is not set in the current theme. |
getColor
public static int getColor (View view, int colorAttributeResId)
Returns the color int for the provided theme color attribute, using the Context
of the
provided view
.
Parameters | |
---|---|
view |
View |
colorAttributeResId |
int |
Returns | |
---|---|
int |
Throws | |
---|---|
IllegalArgumentException |
if the attribute is not set in the current theme. |
layer
public static int layer (View view, int backgroundColorAttributeResId, int overlayColorAttributeResId, float overlayAlpha)
Convenience method that wraps layer(int, int, float)
for layering colors
from theme attributes.
Parameters | |
---|---|
view |
View |
backgroundColorAttributeResId |
int |
overlayColorAttributeResId |
int |
overlayAlpha |
float |
Returns | |
---|---|
int |
layer
public static int layer (int backgroundColor, int overlayColor)
Calculates a color that represents the layering of the overlayColor
on top of the
backgroundColor
.
Parameters | |
---|---|
backgroundColor |
int |
overlayColor |
int |
Returns | |
---|---|
int |
layer
public static int layer (View view, int backgroundColorAttributeResId, int overlayColorAttributeResId)
Convenience method that calculates layer(View, int, int, float)
without
an overlayAlpha
value by passing in 1f
for the alpha value.
Parameters | |
---|---|
view |
View |
backgroundColorAttributeResId |
int |
overlayColorAttributeResId |
int |
Returns | |
---|---|
int |
layer
public static int layer (int backgroundColor, int overlayColor, float overlayAlpha)
Calculates a color that represents the layering of the overlayColor
(with overlayAlpha
applied) on top of the backgroundColor
.
Parameters | |
---|---|
backgroundColor |
int |
overlayColor |
int |
overlayAlpha |
float |
Returns | |
---|---|
int |