> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# LynxTheme

The light or dark appearance the app is drawn in, the device's own, and on Android its wallpaper's colors, as signals. `import { LynxTheme, provideColorScheme } from '@blotch/angular-lynx';`

## Usage

```typescript title="src/app/app.ts"
import { Component, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxTheme } from '@blotch/angular-lynx';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS],
  template: `
    <view (bindtap)="theme.setColorScheme('dark')">
      <text class="app-text">Drawn {{ theme.appearance() }}</text>
    </view>
  `,
})
export class App {
  readonly theme = inject(LynxTheme);
}
```

The `page` element has the `dark` class while `appearance()` is `'dark'`, so a stylesheet's dark values go under `page.dark`. See [Dark mode](/guide/dark-mode.md).

## API

### `LynxTheme`

```typescript
@Injectable({ providedIn: 'root' })
class LynxTheme {}
```

Reads the `theme` value that the [host app](/guide/glossary.md#host-app) sets in its global data. The host usually sets it from the operating system's appearance setting. In the web preview, where no host sets one, it's the browser's `prefers-color-scheme`.

### `LynxTheme.appearance`

```typescript
readonly appearance: Signal<'light' | 'dark'>;
```

What the app is drawn in: its own choice (see `colorScheme`), or the device's while that's `'system'`.

### `LynxTheme.colorScheme`

```typescript
readonly colorScheme: Signal<LynxColorScheme>;
```

The app's choice: `'system'` (the default) follows the device, and `'light'` and `'dark'` keep to one.

### `LynxTheme.setColorScheme()`

```typescript
setColorScheme(scheme: LynxColorScheme): void;
```

Sets the app's choice. It lasts until the app closes: store the user's choice and set it again at the next start.

### `LynxTheme.theme`

```typescript
readonly theme: Signal<'Light' | 'Dark'>;
```

The device's theme, whatever the app chose. `'Light'` when the host sets none and no browser prefers dark.

### `LynxTheme.isDarkMode`

```typescript
readonly isDarkMode: Signal<boolean>;
```

`true` when `theme()` is `'Dark'`.

### `provideColorScheme()`

```typescript
function provideColorScheme(scheme: LynxColorScheme): EnvironmentProviders;
```

Sets the app's choice from its first frame, in `app.config.ts`. An app with no dark design uses `provideColorScheme('light')`.

### `LynxTheme.dynamicColors`

```typescript
readonly dynamicColors: Signal<DynamicColors | null>;
```

The colors Android 12 and later take from the user's wallpaper (Material You's **dynamic color**), as [Material 3's color roles](https://m3.material.io/styles/color/roles), in a light and a dark scheme. `null` where the host app sends none.

```typescript
const theme = inject(LynxTheme);

// The wallpaper's tertiary color, or your own where there's none.
const accent = computed(
  () => theme.dynamicColors()?.light.tertiary ?? '#7d5260',
);
```

- **It comes from the host app,** in its `dynamicColors` GlobalData value: `{ light, dark }`, each with a hex color, such as `#6750a4`, for every role in `DYNAMIC_COLOR_ROLES`. A scheme with a role missing counts as none.
- **The Android app [`ng build --platform android`](/guide/building-for-production.md) builds sends it**, and sends it again when the user changes their wallpaper or colors. iOS, the web preview and Lynx Explorer have none.
- **Both schemes come at once,** so an app that keeps its own light or dark theme can use the right one.
- **To color the UI components with it,** use [Dynamic Color](/dolan/dynamic-color.md).

## Types

### `LynxColorScheme`

```typescript
type LynxColorScheme = 'system' | 'light' | 'dark';
```

### `LynxAppearance`

```typescript
type LynxAppearance = 'light' | 'dark';
```

### `DynamicColors`

```typescript
type DynamicColors = {
  readonly light: DynamicColorScheme;
  readonly dark: DynamicColorScheme;
};
```

### `DynamicColorScheme`

```typescript
type DynamicColorScheme = { readonly [R in DynamicColorRole]: string };
```

Each role's color, as a hex color such as `#6750a4`.

### `DynamicColorRole`

One of Material's color roles, as `DYNAMIC_COLOR_ROLES` lists them:

- `primary`, `onPrimary`, `primaryContainer`, `onPrimaryContainer`, `inversePrimary`
- `secondary`, `onSecondary`, `secondaryContainer`, `onSecondaryContainer`
- `tertiary`, `onTertiary`, `tertiaryContainer`, `onTertiaryContainer`
- `background`, `onBackground`, `surface`, `onSurface`, `surfaceVariant`, `onSurfaceVariant`
- `surfaceDim`, `surfaceBright`, `surfaceContainerLowest`, `surfaceContainerLow`, `surfaceContainer`, `surfaceContainerHigh`, `surfaceContainerHighest`
- `inverseSurface`, `inverseOnSurface`, `outline`, `outlineVariant`

The error roles aren't there: Material keeps errors red whatever the wallpaper.

## Related

- [Dark mode](/guide/dark-mode.md): switch your styles with the theme.
- [Dynamic Color](/dolan/dynamic-color.md): color the UI components with the wallpaper's colors.
- [Host data](/api/angular-lynx/host/host-data.md): `LynxGlobalData`, where the value comes from.
- [System info](/api/angular-lynx/device/system-info.md)
