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
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:
- There are no colors to set. It sets the theme's own variables, such as
--primaryand--secondary, to the wallpaper's. The components' Material designs, and your ownbg-primaryandtext-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:
ring-subtleis the primary at 40%, as in the theme.- Each color's
-rgbtwin changes with it, so opacity modifiers such asbg-primary/10follow too. - The rest stay the theme's. Material keeps errors red, so
destructivedoesn't change. Thechart-*colors tell data apart, so they don't either, and nor do clear glass's white andglass-dim.
Use the colors yourself
LynxTheme.dynamicColors() has all 30 roles, in light and dark, such as tertiary for an accent of your own:
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.
Accessibility
- Material's roles keep text readable. Each
oncolor 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.
