How to supply an image to create and apply a dynamic content based color scheme?

238 Views Asked by At

The Material 3 Design guidelines describes the option of theming based on content (instead of theming based on the current wallpaper of the user). See below for the section:

https://m3.material.io/styles/color/dynamic-color/user-generated-color#8af550b9-a19e-4e9f-bb0a-7f611fed5d0f

Now applying a dynamic theme to an activity on android works with:

DynamicColors.applyToActivityIfAvailable(this);

But how do you:

  1. Generate a theme based on content (preferably using a view or an image)?
  2. Apply that generated theme?

Are there methods available for this?

1

There are 1 best solutions below

1
On

This functionality is only available with the material-components-android version 1.10 currently in alpha.

    DynamicColors.applyToActivityIfAvailable(
    this,
    new DynamicColorsOptions.Builder()
        .setContentBasedSource(bitmap)
        .build()
);

Content-based Dynamic Colors are explained in the MDC documentation on Color: https://github.com/material-components/material-components-android/blob/master/docs/theming/Color.md#content-based-dynamic-colors