Skip to content

SaltUI theme ​

Wrap an application or independent window in SaltTheme. Descendant components use its colors, typography, spacing, shapes, and interaction feedback.

Configure the theme ​

kotlin
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.

ConfigurationControls
configsLight or dark mode and input feedback
dynamicColorsLight and dark color sets
textStylesTypography roles
dimensSizes and spacing
shapesShapes and rounded corners
materialBackground material
basicScreenStyleScreen styling
glassEffectDefault 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.

kotlin
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 ​

RolesUse
highlight, onHighlightAccent or primary actions and the content drawn over them
text, subTextPrimary and supporting text
background, subBackground, popupPage, card, and popup surfaces
strokeBorders
success, warning, errorSemantic status colors

Configure each surface at its own layer. See menu color and material for the role of popup.

kotlin
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.

kotlin
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.

kotlin
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.

kotlin
Box(
    modifier = Modifier
        .clip(SaltTheme.shapes.medium)
        .background(SaltTheme.colors.subBackground)
        .innerPadding()
) {
    Text(text = "Custom container")
}

Google/Android 是 Google LLC 的注册商标,Salt Player 和糖醋音乐均是寻浔科技(上海)有限公司在中华人民共和国的注册商标