Closed Boehrsi closed 2 years ago
Did you find any workaround?
Yes, but it's some manual work. I created some wrappers, but as a summary you could do something like this:
createMdcTheme()
and manually overloads the colors for the dark mode// colors, typography and shapes are obtained via `createMdcTheme()`
MaterialTheme(
colors = adjustColors(colors, isDarkMode),
typography = typography,
shapes = shapes
) {
content()
}
// background, onBackground etc. are obtained via e.g. `ContextCompat.getColor(context, R.color.your_desired_background)`
fun adjustColors(colors: Colors, isDarkMode: Boolean): Colors {
return if (isDarkMode) {
colors.copy(
background = Color(background),
onBackground = Color(onBackground),
surface = Color(surface),
onSurface = Color(onSurface),
error = Color(error),
isLight = false
)
} else {
colors
}
}
Thank you. I don't think you even need to override the darkmode colors manually? I got it working like this, I believe:
val (colorScheme, typography) = createMdcTheme(
context = context, LayoutDirection.Ltr
)
MaterialTheme(
colors = colorScheme!!,
typography = typography!!,
) {
... composable content here
}
setDefaultNightMode is taken into account, it takes the correct colors from my -night theme.
That sounds pretty nice! I implemented the workaround some versions ago, potentially it's now easier to get a working dark / light flow here. Thanks for the hint. I will check this in the next week. Potentially this issue then can be closed.
@Frank1234 I just double checked this in the project where I initially had the problem. I can confirm everything is working now. Closing this as it's working as intended now (tested with version 1.1.5).
Situation / problem: I'm currently using Compose in conjunction with views and I'm utilizing my already defined Material Design theme via the MDC-Android Compose Theme Adapter. This works actually great, except for a dark mode applied in app via
AppCompatDelegate.setDefaultNightMode(darkMode)
and not system wide. The app always stays in the system wide defined theme. That makes actually sense as the ComponentActivity isn't aware of the AppCompat part.Fix idea: It would be great if this could "just work" somehow, but I'm unaware if this is somehow possible. As an easy fix and addition to this library it would be great to just have a switch for the
MdcTheme()
constructor or thecreateMdcTheme()
method, to manually set the mode to dark or light.Used library version: 1.0.1