Reputation: 93
I wrote some Jetpack Compose Demo, but I found library bug about adapt dark mode, therefore I want to show light mode only in my App, however when I set <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
and AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
, those do not work, any idea for show light mode only for Jetpack Compose?
Upvotes: 9
Views: 7130
Reputation: 71
on theme.kt change this
val colors = if (darkTheme) {
DarkColorPalette
} else {
LightColorPalette
}
to this
val colors = LightColorPalette
Upvotes: 2
Reputation:
Simply add an item in both res/theme.xml and res/theme.xml(night) file is <item name="android:windowBackground">@color/white</item>
in both darkand light mode it will be white.
Thank you.
Upvotes: 1
Reputation: 1478
The color we used for compose is not defined in xml, should be something like below:
@Composable
fun MyComposeTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
val colors = if (darkTheme) {
DarkColorPalette
} else {
LightColorPalette
}
MaterialTheme(
colorScheme = colors,
content = content
)
}
As you can see, you can pass any color as you wish in MaterialTheme function call, just remove the dark mode check will do the trick.
Upvotes: 5