kotlinuser-interfaceandroid-jetpack-composeandroid-darkmode

Is there a way not to switch to darkmode while system is in darkmode in jetpack?


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


Solution

  • 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.