SaltUI theme
Wrap an application or independent window in SaltTheme. Descendant components use its colors, typography, spacing, shapes, and interaction feedback.
Configure the theme
SaltTheme(
configs = SaltConfigs.default(isDarkTheme = isDarkTheme),
dynamicColors = SaltDynamicColors(
light = SaltColors.defaultLight(),
dark = SaltColors.defaultDark()
)
) {
// App content.
}Pass the dark-mode setting from your app or system. SaltConfigs.default() starts in light mode. Use SaltConfigs.default(), SaltColors.defaultLight(), and SaltColors.defaultDark() in new code.
| Configuration | Controls |
|---|---|
configs | Light or dark mode and input feedback |
dynamicColors | Light and dark color sets |
textStyles | Typography roles |
dimens | Sizes and spacing |
shapes | Shapes and rounded corners |
material | Background material |
basicScreenStyle | Screen styling |
glassEffect | Default Glass effect |
material, basicScreenStyle, and glassEffect are unstable APIs.
Dark mode and interaction feedback
Read SaltTheme.configs.isDarkTheme in composition. To change just the appearance locally, copy the existing config so its indication is preserved.
SaltTheme(
configs = SaltTheme.configs.copy(isDarkTheme = true)
) {
Text(text = "Dark content")
}SaltConfigs.default() uses a ripple. Pass a different Indication if the app has its own feedback. Each nested SaltTheme gets its own material-source scope. Use ChangeSaltThemeIsDark to change light or dark mode while sharing the existing source. See Material scope.
Colors
SaltDynamicColors holds light and dark palettes. SaltTheme.colors resolves the current one.
SaltColors
| Roles | Use |
|---|---|
highlight, onHighlight | Accent or primary actions and the content drawn over them |
text, subText | Primary and supporting text |
background, subBackground, popup | Page, card, and popup surfaces |
stroke | Borders |
success, warning, error | Semantic status colors |
Configure each surface at its own layer. See menu color and material for the role of popup.
SaltTheme(
dynamicColors = SaltDynamicColors(
light = SaltColors.defaultLight(highlight = Color(0xFF006C4C)),
dark = SaltColors.defaultDark(highlight = Color(0xFF70DBAF))
)
) {
// Use the custom accent color.
}Map Material 3 colors
Choose explicit mappings for the colors an app shares across themes. The example maps Material 3 colors to a SaltUI light or dark palette.
fun ColorScheme.toSaltColors(): SaltColors = SaltColors.defaultLight(
highlight = primary,
onHighlight = onPrimary,
text = onSurface,
subText = onSurfaceVariant,
background = background,
subBackground = surface,
popup = surfaceContainer,
stroke = outline,
error = error
)Typography
SaltTextStyles supplies typography roles. Text color comes from the component or from SaltTheme.colors.
Text(
text = "Additional information",
style = SaltTheme.textStyles.sub,
color = SaltTheme.colors.subText
)Sizes and spacing
Use SaltTheme.dimens and the padding modifiers to align custom content with built-in components.
Shapes
Use SaltTheme.shapes to reuse the app's shape roles in custom content.
Box(
modifier = Modifier
.clip(SaltTheme.shapes.medium)
.background(SaltTheme.colors.subBackground)
.innerPadding()
) {
Text(text = "Custom container")
}