applyToActivitiesIfAvailable

open fun applyToActivitiesIfAvailable(@NonNull application: Application, @NonNull colorContrastOptions: ColorContrastOptions)

Applies contrast to all activities 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();
    ColorContrast.applyToActivitiesIfAvailable(this);
  }
}

This method will try to apply a theme overlay in every activity's onActivityPreCreated callback.

Parameters

application

The target application.

colorContrastOptions

The color contrast options object that specifies the theme overlay resource IDs for medium and high contrast mode.