Last active
December 7, 2022 11:52
-
-
Save MrNtlu/4737e591040649745b45346372394fff to your computer and use it in GitHub Desktop.
Jetpack Compose Dark Theme Theme File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val DarkColorPalette = darkColorScheme( | |
primary = PrimaryDark, | |
onPrimary = OnPrimaryDark, | |
primaryContainer = PrimaryContainerDark, | |
onPrimaryContainer = OnPrimaryContainerDark, | |
secondary = SecondaryDark, | |
onSecondary = OnSecondaryDark, | |
secondaryContainer = SecondaryContainerDark, | |
onSecondaryContainer = OnSecondaryContainerDark, | |
tertiary = TertiaryDark, | |
onTertiary = OnTertiaryDark, | |
tertiaryContainer = TertiaryContainerDark, | |
onTertiaryContainer = OnTertiaryContainerDark, | |
error = ErrorDark, | |
onError = OnErrorDark, | |
errorContainer = ErrorContainerDark, | |
onErrorContainer = OnErrorContainerDark, | |
background = BackgroundDark, | |
onBackground = OnBackgroundDark, | |
surface = SurfaceDark, | |
outline = OutlineDark, | |
surfaceVariant = SurfaceVariantDark, | |
onSurfaceVariant = OnSurfaceVariantDark, | |
) | |
private val LightColorPalette = lightColorScheme( | |
primary = PrimaryLight, | |
onPrimary = OnPrimaryLight, | |
primaryContainer = PrimaryContainerLight, | |
onPrimaryContainer = OnPrimaryContainerLight, | |
secondary = SecondaryLight, | |
onSecondary = OnSecondaryLight, | |
secondaryContainer = SecondaryContainerLight, | |
onSecondaryContainer = OnSecondaryContainerLight, | |
tertiary = TertiaryLight, | |
onTertiary = OnTertiaryLight, | |
tertiaryContainer = TertiaryContainerLight, | |
onTertiaryContainer = OnTertiaryContainerLight, | |
error = ErrorLight, | |
onError = OnErrorLight, | |
errorContainer = ErrorContainerLight, | |
onErrorContainer = OnErrorContainerLight, | |
background = BackgroundLight, | |
onBackground = OnBackgroundLight, | |
surface = SurfaceLight, | |
outline = OutlineLight, | |
surfaceVariant = SurfaceVariantLight, | |
onSurfaceVariant = OnSurfaceVariantLight, | |
) | |
@Composable | |
fun JetpackComposeDarkThemeTheme( | |
darkTheme: Boolean = isSystemInDarkTheme(), | |
content: @Composable () -> Unit | |
) { | |
val colors = if (darkTheme) { | |
DarkColorPalette | |
} else { | |
LightColorPalette | |
} | |
MaterialTheme( | |
colorScheme = colors, | |
typography = Typography, | |
shapes = Shapes, | |
content = content | |
) | |
// Optional, this part helps you set the statusbar color | |
val view = LocalView.current | |
if (!view.isInEditMode) { | |
SideEffect { | |
val window = (view.context as Activity).window | |
window.statusBarColor = colors.background.toArgb() | |
WindowCompat.getInsetsController(window, view) | |
.isAppearanceLightStatusBars = !darkTheme | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment