Android 12 (API 31) introduced dynamic color, the heart of Material You 15,533 : the system derives tonal palettes from the user's wallpaper, and dynamicLightColorScheme(context) and dynamicDarkColorScheme(context) turn them into a complete ColorScheme. Supporting it is one branch in the theme function:
@Composable
fun BookNestTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
dynamicColor: Boolean = false, // brand colors unless asked
content: @Composable () -> Unit,
) {
val context = LocalContext.current
val colors = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
darkTheme -> BookNestDark
else -> BookNestLight
}
MaterialTheme(colorScheme = colors, typography = BookNestTypography,
shapes = BookNestShapes, content = content)
}Both functions are @RequiresApi(31), and BookNest's minSdk is 26, hence the version check. The gallery logs its roles; with BookNest's scheme and then with the switch on (or --ez dynamic true), it printed:
D/BookNestTheme: dark=false dynamic=false primary=#3C6939 primaryContainer=#BCF0B4 surface=#F7FBF1 D/BookNestTheme: dark=false dynamic=true primary=#495D92 primaryContainer=#DAE2FF surface=#FAF8FF
The emulator's default wallpaper produces blue. Dynamic color makes an app feel native to the user's phone, but it erases your brand color and varies per device. The Android Studio 234 template defaults dynamicColor = true; BookNest defaults to false and offers it as a setting. Test both: a hard-coded color that looks fine next to green can clash with a wallpaper-derived pink.