https://kotlinlang.org logo
#compose
Title
# compose
a

amar_1995

09/06/2020, 3:10 PM
I need to provide in-app dark and light theme feature. Currently, I am changing theme using
isSystemInDarkTheme
but how to change theme using user input ?
f

flosch

09/06/2020, 3:13 PM
Just have a separate value stored somewhere that switches the colors of your theme (e.g.
MaterialTheme
). e.g.
Copy code
var userWantsDarkTheme by remember { mutableStateOf(false) }
val colors = when {
    isSystemInDarkTheme() && userWantsDarkTheme -> darkColors()
    else -> lightColors()
}
MaterialTheme(colors = colors) { Content() }
a

amar_1995

09/06/2020, 3:18 PM
Thanks
I tried the above approach but when theme state changes app get refreshed
Is there any way to resolve above
6 Views