wrapContextIfAvailable

open fun wrapContextIfAvailable(@NonNull originalContext: Context): Context

Wraps the given context with the theme overlay designated by the theme attribute dynamicColorThemeOverlay. The returned context can be used to create views with dynamic color support.

If dynamic color support or the dynamic color theme overlay is not available, the original context will be returned.

Parameters

originalContext

The original context.


open fun wrapContextIfAvailable(@NonNull originalContext: Context, @StyleRes theme: Int): Context

Wraps the given context with the given theme overlay. The returned context can be used to create views with dynamic color support.

If dynamic color support is not available, the original context will be returned.

Parameters

originalContext

The original context.

theme

The resource ID of the theme overlay that provides dynamic color definition.


open fun wrapContextIfAvailable(@NonNull originalContext: Context, @NonNull dynamicColorsOptions: DynamicColorsOptions): Context

Wraps the given context with the given theme overlay provided in DynamicColorsOptions. The returned context can be used to create views with dynamic color support.

If dynamic color support is not available, the original context will be returned.

Parameters

originalContext

The original context.

dynamicColorsOptions

The dynamic colors options object that specifies the theme resource ID, seed color for content-based dynamic colors.