applyToActivitiesIfAvailable

Applies dynamic colors to all activities with the theme overlay designated by the theme attribute dynamicColorThemeOverlay by registering a ActivityLifecycleCallbacks to your application.

Parameters

application

The target application.

See also


open fun applyToActivitiesIfAvailable(@NonNull application: Application, @NonNull dynamicColorsOptions: DynamicColorsOptions)

Applies dynamic colors to all activities based on the provided DynamicColorsOptions, by registering a ActivityLifecycleCallbacks to your application.

A normal usage of this method should happen only once in onCreate or any methods that run before any of your activities are created. For example:

public class YourApplication extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
    DynamicColors.applyToActivitiesWithCallbacks(this);
  }
}
This method will try to apply the given dynamic color theme overlay in every activity's onActivityPreCreated callback. Therefore, if you are applying any other theme overlays after that, you will need to be careful about not overriding the colors or you may lose the dynamic color support.

Parameters

application

The target application.

dynamicColorsOptions

The dynamic colors options object that specifies the theme resource ID, precondition to decide if dynamic colors should be applied and the callback function for after dynamic colors have been applied.


open fun applyToActivitiesIfAvailable(@NonNull application: Application, @StyleRes theme: Int)

Deprecated

Use applyToActivitiesIfAvailable instead.

Applies dynamic colors to all activities with the given theme overlay by registering a to your application.

Parameters

application

The target application.

theme

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


Deprecated

Use applyToActivitiesIfAvailable instead.

Applies dynamic colors to all activities with the theme overlay designated by the theme attribute dynamicColorThemeOverlay according to the given precondition by registering a ActivityLifecycleCallbacks to your application.

Parameters

application

The target application.

precondition

The precondition to decide if dynamic colors should be applied.


Deprecated

Use applyToActivitiesIfAvailable instead.

Applies dynamic colors to all activities with the given theme overlay according to the given precondition by registering a ActivityLifecycleCallbacks to your application.

Parameters

application

The target application.

theme

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

precondition

The precondition to decide if dynamic colors should be applied.