---
title: "dynamicColorScheme"
description: "Creates a dynamic color scheme."
type: "function"
lastmod: "2026-07-19T07:47:45.559671Z"
---
## API Reference

### dynamicColorScheme

> Source set: Android

```kotlin
public fun dynamicColorScheme(context: Context): ColorScheme?
```

Creates a dynamic color scheme.

Use this function to create a color scheme based on the current watchface. If the user changes
the watchface colors, this color scheme will change accordingly. This function checks whether the
dynamic color scheme can be used and returns null otherwise. It is expected that callers will
check the return value and fallback to their own default color scheme if it is null.

Example using a dynamic color scheme to theme buttons in a column:

#### Parameters

| | |
| --- | --- |
| context | The context required to get system resource data. |

## Code Examples
### DynamicColorSchemeSample
```kotlin
@Composable
fun DynamicColorSchemeSample() {
    val dynamicColorScheme = dynamicColorScheme(LocalContext.current)
    val transformationSpec = rememberTransformationSpec()
    // Fallback to the default color scheme if dynamic colors are unavailable
    MaterialTheme(colorScheme = dynamicColorScheme ?: ColorScheme()) {
        val hasDynamicColors = dynamicColorScheme != null
        TransformingLazyColumn(
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.spacedBy(4.dp),
            contentPadding = PaddingValues(20.dp),
        ) {
            if (!hasDynamicColors) {
                item { Text("Dynamic color is not available.") }
            }
            items(5) { index ->
                // The button's defaults will pick up the dynamic primary color from the
                // MaterialTheme
                Button(
                    label = { Text("Primary Button ${index + 1}") },
                    modifier =
                        Modifier.fillMaxWidth()
                            .transformedHeight(this, transformationSpec)
                            .minimumVerticalContentPadding(
                                ButtonDefaults.minimumVerticalListContentPadding
                            ),
                    onClick = {},
                    transformation = SurfaceTransformation(transformationSpec),
                )
            }
        }
    }
}
```
