HarmonizedColors

public class 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, and wrapContextIfAvailable

Summary

Public methods

static void
applyToContextIfAvailable(
    Context context,
    HarmonizedColorsOptions options
)

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

static boolean

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.

Public methods

applyToContextIfAvailable

public static void applyToContextIfAvailable(
    Context context,
    HarmonizedColorsOptions options
)

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

If harmonization is not available, provided color resources and attributes in will not be harmonized.

Parameters
Context context

The target context.

HarmonizedColorsOptions options

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

Parameters
Context context

The target context.

HarmonizedColorsOptions options

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.