# HarmonizedColors

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

*** ** * ** ***


```
public class HarmonizedColors
```

<br />

*** ** * ** ***

A class for harmonizing color resources and attributes.

This class is used for harmonizing color resources/attributes defined in xml at runtime. The values of harmonized resources/attributes will be overridden, and afterwards if you retrieve the value from the associated context, or inflate resources like layouts that are using those harmonized resources/attributes, the overridden values will be used instead.

If you need to harmonize color resources at runtime, see: `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColors#applyToContextIfAvailable(Context,com.google.android.material.color.HarmonizedColorsOptions)`, and `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColors#wrapContextIfAvailable(Context,com.google.android.material.color.HarmonizedColorsOptions)`

## Summary

| ### Public methods |
|---|---|
| `static void` | `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColors#applyToContextIfAvailable(Context,com.google.android.material.color.HarmonizedColorsOptions)( Context context, https://developer.android.com/reference/com/google/android/material/color/HarmonizedColorsOptions options )` Harmonizes the specified color resources, attributes, and theme overlay in the Context provided. |
| `static boolean` | `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColors#isHarmonizedColorAvailable()()` If harmonization is not available, color will not be harmonized. |
| `static Context` | `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColors#wrapContextIfAvailable(Context,com.google.android.material.color.HarmonizedColorsOptions)( Context context, https://developer.android.com/reference/com/google/android/material/color/HarmonizedColorsOptions options )` Wraps the given Context from HarmonizedColorsOptions with the color resources being harmonized. |

## Public methods

### applyToContextIfAvailable

```
public static void applyToContextIfAvailable(
    Context context,
    HarmonizedColorsOptions options
)
```

Harmonizes the specified color resources, attributes, and theme overlay in the Context provided.

If harmonization is not available, provided color resources and attributes in `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColorsOptions` will not be harmonized.

| Parameters |
|---|---|
| `Context context` | The target context. |
| `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColorsOptions options` | The `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColorsOptions` object that specifies the resource ids, color attributes to be harmonized and the color attribute to harmonize with. |

### isHarmonizedColorAvailable

```
public static boolean isHarmonizedColorAvailable()
```

If harmonization is not available, color will not be harmonized.

| Returns |
|---|---|
| `boolean` | `true` if harmonized colors are available on the current SDK level, otherwise `false` will be returned. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColors#applyToContextIfAvailable(Context,com.google.android.material.color.HarmonizedColorsOptions)` |   |
| `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColors#wrapContextIfAvailable(Context,com.google.android.material.color.HarmonizedColorsOptions)` |   |

### wrapContextIfAvailable

```
public static Context wrapContextIfAvailable(
    Context context,
    HarmonizedColorsOptions options
)
```

Wraps the given Context from HarmonizedColorsOptions with the color resources being harmonized.

If harmonization is not available, provided color resources and attributes in `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColorsOptions` will not be harmonized.

| Parameters |
|---|---|
| `Context context` | The target context. |
| `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColorsOptions options` | The `https://developer.android.com/reference/com/google/android/material/color/HarmonizedColorsOptions` object that specifies the resource ids, color attributes to be harmonized and the color attribute to harmonize with. |

| Returns |
|---|---|
| `Context` | the new context with resources being harmonized. If resources are not harmonized successfully, the context passed in will be returned. |