# MaterialColors

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/color/MaterialColors.java)

*** ** * ** ***


```
public class MaterialColors
```

<br />

*** ** * ** ***

A utility class for common color variants used in Material themes.

## Summary

| ### Constants |
|---|---|
| `static final float` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#ALPHA_DISABLED() = 0.38f` |
| `static final float` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#ALPHA_DISABLED_LOW() = 0.12f` |
| `static final float` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#ALPHA_FULL() = 1.0f` |
| `static final float` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#ALPHA_LOW() = 0.32f` |
| `static final float` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#ALPHA_MEDIUM() = 0.54f` |

| ### Public methods |
|---|---|
| `static int` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#compositeARGBWithAlpha(int,int)(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` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#getColor(View,int)(View view, int colorAttributeResId)` Returns the color int for the provided theme color attribute, using the Context of the provided `view`. |
| `static int` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#getColor(Context,int,int)(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` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#getColor(Context,int,java.lang.String)( Context context, int colorAttributeResId, https://developer.android.com/reference/java/lang/String errorMessageComponent )` Returns the color int for the provided theme color attribute. |
| `static int` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#getColor(View,int,int)(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 https://developer.android.com/reference/java/lang/Integer` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#getColorOrNull(Context,int)(Context context, int colorAttributeResId)` Returns the color int for the provided theme color attribute, or null if the attribute is not set in the current theme. |
| `static https://developer.android.com/reference/com/google/android/material/color/ColorRoles` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#getColorRoles(int,boolean)(int color, boolean isLightTheme)` Returns the `https://developer.android.com/reference/com/google/android/material/color/ColorRoles` object generated from the provided input color. |
| `static https://developer.android.com/reference/com/google/android/material/color/ColorRoles` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#getColorRoles(Context,int)(Context context, int color)` Returns the `https://developer.android.com/reference/com/google/android/material/color/ColorRoles` object generated from the provided input color. |
| `static ColorStateList` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#getColorStateList(Context,int,ColorStateList)( Context context, int colorAttributeResId, ColorStateList defaultValue )` Returns the color state list for the provided theme color attribute, or the default value if the attribute is not set in the current theme. |
| `static ColorStateList` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#getColorStateListOrNull(Context,int)(Context context, int colorAttributeResId)` Returns the color state list for the provided theme color attribute, or null if the attribute is not set in the current theme. |
| `static int` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#harmonize(int,int)(int colorToHarmonize, int colorToHarmonizeWith)` A convenience function to harmonize any two colors provided, returns the color int of the harmonized color, or the original design color value if color harmonization is not available. |
| `static int` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#harmonizeWithPrimary(Context,int)(Context context, int colorToHarmonize)` Returns the color int of the given color harmonized with the context theme's colorPrimary. |
| `static boolean` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#isColorLight(int)(int color)` Determines if a color should be considered light or dark. |
| `static int` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#layer(int,int)(int backgroundColor, int overlayColor)` Calculates a color that represents the layering of the `overlayColor` on top of the `backgroundColor`. |
| `static int` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#layer(int,int,float)(int backgroundColor, int overlayColor, float overlayAlpha)` Calculates a color that represents the layering of the `overlayColor` (with ` overlayAlpha` applied) on top of the `backgroundColor`. |
| `static int` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#layer(View,int,int)( View view, int backgroundColorAttributeResId, int overlayColorAttributeResId )` Convenience method that calculates `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#layer(View,int,int,float)` without an `overlayAlpha` value by passing in `1f` for the alpha value. |
| `static int` | `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#layer(View,int,int,float)( View view, int backgroundColorAttributeResId, int overlayColorAttributeResId, float overlayAlpha )` Convenience method that wraps `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#layer(int,int,float)` for layering colors from theme attributes. |

## Constants

### ALPHA_DISABLED

```
public static final float ALPHA_DISABLED = 0.38f
```

### ALPHA_DISABLED_LOW

```
public static final float ALPHA_DISABLED_LOW = 0.12f
```

### ALPHA_FULL

```
public static final float ALPHA_FULL = 1.0f
```

### ALPHA_LOW

```
public static final float ALPHA_LOW = 0.32f
```

### ALPHA_MEDIUM

```
public static final float ALPHA_MEDIUM = 0.54f
```

## 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 |
|---|---|
| `int originalARGB` | The original color. |
| `int alpha` | The additional alpha \[0-255\]. |

| Returns |
|---|---|
| `int` | The blended color. |

### 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`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the attribute is not set in the current theme. |

### 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.

### getColor

```
public static int getColor(
    Context context,
    int colorAttributeResId,
    String errorMessageComponent
)
```

Returns the color int for the provided theme color attribute.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the attribute is not set in the current theme. |

### 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.

### getColorOrNull

```
public static Integer getColorOrNull(Context context, int colorAttributeResId)
```

Returns the color int for the provided theme color attribute, or null if the attribute is not set in the current theme.

### getColorRoles

```
public static ColorRoles getColorRoles(int color, boolean isLightTheme)
```

Returns the `https://developer.android.com/reference/com/google/android/material/color/ColorRoles` object generated from the provided input color.

| Parameters |
|---|---|
| `int color` | The input color provided for generating its associated four color roles. |
| `boolean isLightTheme` | Whether the input is light themed or not, true if light theme is enabled. |

### getColorRoles

```
public static ColorRoles getColorRoles(Context context, int color)
```

Returns the `https://developer.android.com/reference/com/google/android/material/color/ColorRoles` object generated from the provided input color.

| Parameters |
|---|---|
| `Context context` | The target context. |
| `int color` | The input color provided for generating its associated four color roles. |

### getColorStateList

```
public static ColorStateList getColorStateList(
    Context context,
    int colorAttributeResId,
    ColorStateList defaultValue
)
```

Returns the color state list for the provided theme color attribute, or the default value if the attribute is not set in the current theme.

### getColorStateListOrNull

```
public static ColorStateList getColorStateListOrNull(Context context, int colorAttributeResId)
```

Returns the color state list for the provided theme color attribute, or null if the attribute is not set in the current theme.

### harmonize

```
public static int harmonize(int colorToHarmonize, int colorToHarmonizeWith)
```

A convenience function to harmonize any two colors provided, returns the color int of the harmonized color, or the original design color value if color harmonization is not available.

| Parameters |
|---|---|
| `int colorToHarmonize` | The color to harmonize. |
| `int colorToHarmonizeWith` | The primary color selected for harmonization. |

### harmonizeWithPrimary

```
public static int harmonizeWithPrimary(Context context, int colorToHarmonize)
```

Returns the color int of the given color harmonized with the context theme's colorPrimary.

| Parameters |
|---|---|
| `Context context` | The target context. |
| `int colorToHarmonize` | The color to harmonize. |

### isColorLight

```
public static boolean isColorLight(int color)
```

Determines if a color should be considered light or dark.

### layer

```
public static int layer(int backgroundColor, int overlayColor)
```

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

### 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`.

### layer

```
public static int layer(
    View view,
    int backgroundColorAttributeResId,
    int overlayColorAttributeResId
)
```

Convenience method that calculates `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#layer(View,int,int,float)` without an `overlayAlpha` value by passing in `1f` for the alpha value.

### layer

```
public static int layer(
    View view,
    int backgroundColorAttributeResId,
    int overlayColorAttributeResId,
    float overlayAlpha
)
```

Convenience method that wraps `https://developer.android.com/reference/com/google/android/material/color/MaterialColors#layer(int,int,float)` for layering colors from theme attributes.