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

Mayank Saini

11/23/2021, 9:22 AM
How can we disable dark mode in compose?
c

Csaba Kozák

11/23/2021, 9:24 AM
Simply always set
lightColors()
to your
MaterialTheme
1
m

Mayank Saini

11/23/2021, 9:27 AM
I tried that but it didn’t work.
c

Csaba Kozák

11/23/2021, 9:30 AM
Please post some code. BTW, are you sure your device not inverting the colors?
m

Mayank Saini

11/23/2021, 9:36 AM
Copy code
private val LightColorPalette = lightColors(
    primary = Primary1,
    primaryVariant = Secondary1,
    onPrimary = Primary1,
    background = Secondary3,
    onBackground = Primary1,
    secondary = Blue05,
    onSecondary = Primary1
    /* Other default colors to override
    background = Color.White,
    surface = Color.White,
    onPrimary = Color.White,
    onSecondary = Color.Black,
    onBackground = Color.Black,
    onSurface = Color.Black,
    */
)

@Composable
fun DigibankTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable() () -> Unit
) {

    MaterialTheme(
        colors = LightColorPalette,
        typography = Typography,
        shapes = Shapes,
        content = content
    )
}
a

Abhinav Suthar

11/23/2021, 9:55 AM
You can disable forced dark mode by running this cmd
adb shell setprop debug.hwui.force_dark false
m

Mayank Saini

11/23/2021, 9:55 AM
I want to disable it for my builds
a

Abhinav Suthar

11/23/2021, 9:57 AM
You code is correct, if you are using MIUI then this issue happens. Either switch to light theme in your device or run this above command using adb
m

Mayank Saini

11/23/2021, 11:32 AM
It doesn’t work for me even on an emulator
c

Chris Sinco [G]

11/23/2021, 6:16 PM
Are you wrapping every Composable with that theme that only passes light colors? There could be an issue with how you setting your theme that is affecting parts of your hierarchy. Screenshots and code snippets in context of UI would also help us debug together.
9 Views