Function

dynamicColorScheme

Creates a dynamic color scheme.

DynamicColorSchemeSample

@Sampled
@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),
                )
            }
        }
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: