Home > front end >  Is there a way not to switch to darkmode while system is in darkmode in jetpack?
Is there a way not to switch to darkmode while system is in darkmode in jetpack?

Time:02-16

I want the same display as in the lightmode when darkmode is on. Is there an easier way without hardcoding every textfields,buttons etc.

CodePudding user response:

If you create a new Jetpack compose project in Android studio, you are likely to get a Theme.kt file with a LightColorPalette, DarkColorPalette and a theme composable. The theme composable usually looks like;

@Composable
fun SampleAppTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable() () -> Unit
) {
    val colors = if (darkTheme) {
        DarkColorPalette
    } else {
        LightColorPalette
    }

    MaterialTheme(
        colors = colors,
        content = content
    )
}

You can just replace isSystemDarkTheme() with false to lock your app into just light theme mode.

  • Related