Setup¶
Installation¶
In your build.gradle.kts file, add Maven Central to your repositories:
Then add CZAN dependency to your module:
Theme customization¶
First, you must configure your theme and define your color palette, typography and shape, as explained in the official documentation for Material 3 with Jetpack Compose.
Colors¶
// Light color scheme
val md_theme_light_primary = Color(0xFF123456)
val MyAppLightColorScheme = lightColorScheme(
primary = md_theme_light_primary,
...
)
// Dark color scheme, if needed
val md_theme_dark_primary = Color(0xFF654321)
val MyAppLightColorScheme = darkColorScheme(
primary = md_theme_dark_primary,
...
)
Typographies¶
val MyAppTypography = Typography(
labelLarge = TextStyle(
fontWeight = FontWeight.Medium,
...
)
...
)
Shapes¶
val MyAppShapes = Shapes(
small = RoundedCornerShape(4.dp),
medium = RoundedCornerShape(8.dp),
large = RoundedCornerShape(12.dp),
extraLarge = RoundedCornerShape(16.dp)
)
Theme usage¶
Once you've customized your theme with colors, typographies and shapes, you can use your theme with CzanTheme. CZAN automatically handles light and dark modes if both color schemes are provided, depending on the device's settings.
@Composable
fun MyAppTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
CzanTheme(
darkTheme = darkTheme,
lightColorScheme = MyAppLightColorScheme,
darkColorScheme = MyAppDarkColorScheme,
typography = MyAppTypography,
shapes = MyAppShapes,
content = content
)
}
Force specific theme
In some cases, you may need to force usage of light or dark mode on specific Composables or screens. (For instance: a custom splash screen which always looks the same on both light and dark modes.)
You can achieve this by using ThemeType.
val themeType: ThemeType = ThemeType.DARK // If you want to use a ThemeType directly from your main Composable
// or
val themeType by viewModel.themeType.collectAsState() // If the ThemeType is provided by the ViewModel
MyAppTheme(darkTheme = shouldUseDarkTheme(themeType = themeType)) {
MyScreen {
...
}
}