HarmonizedColors

public class HarmonizedColors
extends Object

java.lang.Object
   ↳ com.google.android.material.color.HarmonizedColors


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: applyToContextIfAvailable(Context, HarmonizedColorsOptions), and wrapContextIfAvailable(Context, HarmonizedColorsOptions)

Summary

Public methods

static void applyToContextIfAvailable(Context context, HarmonizedColorsOptions options)

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

static boolean isHarmonizedColorAvailable()

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

static Context wrapContextIfAvailable(Context context, HarmonizedColorsOptions options)

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

Inherited methods

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 HarmonizedColorsOptions will not be harmonized.

Parameters
context Context: The target context.

options HarmonizedColorsOptions: The 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.

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 HarmonizedColorsOptions will not be harmonized.

Parameters
context Context: The target context.

options HarmonizedColorsOptions: The 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.