Creates a dynamic color scheme.
DynamicColorSchemeSample
@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),
)
}
}
}
}