For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /dolan/dynamic-color.md.

Dynamic Color

Give your app the colors of the user's wallpaper on Android 12 and later, as Material You apps have them. One directive recolors the theme, and every component follows.

The preview runs in your browser, which has no wallpaper, so it shows the theme as it is. Build the example for Android with ng build --platform android --run to see it take your wallpaper's colors.

Installation

npx @blotch/dolan add dynamic-color
import { UiDynamicColor } from '../components/ui/dynamic-color';
Tip

Dynamic Color depends on Icon, whose copy of the theme it colors too. dolan add installs it automatically.

Usage

Put uiDynamicColor on your root view:

src/app/app.ts
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';
import { UiDynamicColor } from '../components/ui/dynamic-color';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS, RouterOutlet, UiDynamicColor],
  template: `
    <view class="h-full bg-background" uiDynamicColor>
      <router-outlet />
    </view>
  `,
})
export class App {}
  • There are no colors to set. It sets the theme's own variables, such as --primary and --secondary, to the wallpaper's. The components' Material designs, and your own bg-primary and text-muted-foreground, follow them.
  • Everything inside the view gets the colors. The page behind it keeps the theme's own background, so give the view bg-background.
  • Icons, glass tints and charts follow too. They draw with a TypeScript copy of the theme, and the directive gives them the same colors.
  • It follows the wallpaper while the app is open. A new wallpaper, new colors in the phone's settings or a dark mode switch restyles the app at once.
  • Elsewhere, nothing changes. On iOS, in the web preview, in Lynx Explorer and before Android 12 there are no wallpaper colors, and the theme stays as it is.

Light and dark

The directive sets the light or the dark colors with the app's appearance, as the theme and the icons pick theirs. The phone's dark mode, or a choice the app makes with LynxTheme.setColorScheme(), switches both.

Which colors change

Each theme color takes one of Material 3's color roles:

Theme colorMaterial role
background, cardsurface
foreground, card-foreground, secondary-foreground, glass-foregroundonSurface
primary, ring, glass-tintprimary
primary-foreground, glass-tint-foregroundonPrimary
secondarysurfaceContainerHigh
mutedsurfaceContainerHighest
muted-foreground, glass-muted-foregroundonSurfaceVariant
accentsecondaryContainer
accent-foregroundonSecondaryContainer
border, inputoutlineVariant
  • ring-subtle is the primary at 40%, as in the theme.
  • Each color's -rgb twin changes with it, so opacity modifiers such as bg-primary/10 follow too.
  • The rest stay the theme's. Material keeps errors red, so destructive doesn't change. The chart-* colors tell data apart, so they don't either, and nor do clear glass's white and glass-dim.

Use the colors yourself

LynxTheme.dynamicColors() has all 30 roles, in light and dark, such as tertiary for an accent of your own:

const theme = inject(LynxTheme);

const accent = computed(
  () => theme.dynamicColors()?.light.tertiary ?? '#7d5260',
);

It's null where there are no wallpaper colors.

In your own native app

The colors come from the host app: the app that ng build --platform android builds sends them as its dynamicColors GlobalData value. If you embed the app in your own, send them the same way. See LynxTheme.dynamicColors for the shape.

API

UiDynamicColor

Selector: [uiDynamicColor]. It has no inputs.

ExportDescription
DYNAMIC_THEME_ROLESThe Material role each theme color takes, as in the table above.
dynamicThemeColors(scheme)A scheme's theme colors, by name without --, each a complete rgba().
UI_THEME_COLORSIn icon-theme.ts: the colors the directive gives the icons, glass tints and charts in it.

Accessibility

  • Material's roles keep text readable. Each on color is made to contrast with the color it sits on.
  • Android 14's contrast setting carries over. At medium or high contrast, Android gives stronger colors, and the app gets them.
  • Theming: the theme's colors and dark mode
  • Glass: the Material designs on Android
  • LynxTheme: the wallpaper's colors as a signal