Complete Example
Here’s a fully functional implementation that checks for Dynamic Color availability, retrieves colors, applies them to your DOM, and listens for theme changes:Wait for Device Ready
The
DynamicColor object is available in the global scope, but only after the deviceready event fires:Always check if Dynamic Color is available using
isDynamicColorAvailable() before using dynamic color features. This ensures compatibility with devices running Android versions below 12.Check Dynamic Color Availability
Before using any Dynamic Color features, verify that the device supports it:
Get and Apply Colors
Retrieve the dynamic colors and apply them to your DOM using CSS variables:The
colorsToDom() and paletteToDom() functions automatically:- Convert colors to CSS variables
- Inject them into the DOM
- Update existing variables when called again
The
tintSurfaceColors() function applies Material Design 3 elevation tints to surface colors, creating subtle variations (surface1 through surface5) for layered UI elements.Listen for Theme Changes
Subscribe to the This event fires when:
dynamicColorChange event to update colors when the user changes their theme or wallpaper:- The user switches between light and dark mode
- The user changes their wallpaper (which updates the color palette)
The
dynamicColorChange event is automatically monitored by the plugin. You just need to add your event listener.Using the Colors in CSS
Once colors are applied to the DOM, you can use them as CSS variables in your stylesheets:Available CSS Variables
System Colors (--md-sys-color-*)
The main color tokens for Material Design 3:
--md-sys-color-primary- Primary brand color--md-sys-color-on-primary- Text/icons on primary--md-sys-color-secondary- Secondary brand color--md-sys-color-on-secondary- Text/icons on secondary--md-sys-color-background- Main background--md-sys-color-on-background- Text/icons on background--md-sys-color-surface- Surface background--md-sys-color-surface1through--md-sys-color-surface5- Tinted surface elevations- And many more (see the API reference for the complete list)
Palette Colors (--md-ref-palette-*)
Tonal variations from 0 (darkest) to 100 (lightest):
--md-ref-palette-primary0through--md-ref-palette-primary100--md-ref-palette-secondary0through--md-ref-palette-secondary100--md-ref-palette-tertiary0through--md-ref-palette-tertiary100--md-ref-palette-neutral0through--md-ref-palette-neutral100--md-ref-palette-error0through--md-ref-palette-error100
Full Working Example
Here’s the complete code from the plugin README:Next Steps
API Reference
Explore all available methods and properties
Guides
See more detailed examples and use cases