Google 致力于为黑人社区推动种族平等。查看具体举措

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 view's Context.

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 Context of the provided view.

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.

static int layer(int backgroundColor, int overlayColor)

Calculates a color that represents the layering of the overlayColor on top of the backgroundColor.

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.

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.

Inherited methods

From class java.lang.Object

Constants

ALPHA_DISABLED

float ALPHA_DISABLED

Constant Value: 0.38

ALPHA_DISABLED_LOW

float ALPHA_DISABLED_LOW

Constant Value: 0.12

ALPHA_FULL

float ALPHA_FULL

Constant Value: 1.0

ALPHA_LOW

float ALPHA_LOW

Constant Value: 0.32

ALPHA_MEDIUM

float ALPHA_MEDIUM

Constant Value: 0.54

Public methods

compositeARGBWithAlpha

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

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

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

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

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

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

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

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

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