With the new color contrast feature in android 15, I have now defined a new color palette for low, medium and high color contrast for both light and dark scheme. How can I apply this dynamically based on what the user has set on his phone ?
Currently, my Theme.kt is like this:
@Composable
fun MesTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> darkScheme
else -> lightScheme
}
// Update the system bar colors
rememberSystemUiController().setSystemBarsColor(
color = colorScheme.background
)
MaterialTheme(
colorScheme = colorScheme,
typography = MesTypography,
shapes = MesShapes,
content = content
)
}
It is only using the light and dark scheme. I need to be able to apply both the medium and high contrast schemes as well.
1