Skip to content

Theme System

Miuix provides a complete theme system that allows you to easily maintain a consistent design style throughout your application. The theme system consists of color schemes and text styles.

Using the Theme

To use the Miuix theme in your application, simply wrap your content in the MiuixTheme composable function:

kotlin
MiuixTheme {
    // Your application content
    Scaffold(
        topBar = { /* ... */ },
    ) { padding ->
        // Main content
    }
}

By default, Miuix automatically selects a light or dark theme suitable for the current system settings.

Color System

The Miuix color system is based on the HyperOS design language and provides a complete set of color schemes, including:

  • Primary colors
  • Secondary colors
  • Background and surface colors
  • Text colors
  • Special state colors (e.g., disabled state)

Key Color Properties

Below are some core properties of the color system:

Property NameDescriptionUsage
primaryPrimary colorSwitches, buttons, sliders
onPrimaryText color on primaryText on primary color
primaryContainerPrimary containerComponents with primary
onPrimaryContainerText on primary containerText on primary containers
secondarySecondary colorSecondary buttons, cards
onSecondaryText on secondaryText on secondary color
backgroundBackground colorApp background
onBackgroundText on backgroundText on background
surfaceSurface colorCards, dialogs
onSurfaceText on surfaceRegular text
onSurfaceSecondarySecondary text on surfaceSecondary text
outlineOutline colorBorders, outlines
dividerLineDivider line colorList dividers
windowDimmingWindow dimming colorDialog, dropdown backgrounds

Using Colors

In composable functions, you can access the current theme's colors via MiuixTheme.colorScheme:

kotlin
val backgroundColor = MiuixTheme.colorScheme.background
val textColor = MiuixTheme.colorScheme.onBackground

Surface(
    color = backgroundColor,
    modifier = Modifier.fillMaxSize()
) {
    Text(
        text = "Hello Miuix!",
        color = textColor
    )
}

Light and Dark Themes

Miuix provides default light and dark theme color schemes:

  • lightColorScheme() - Light theme color scheme
  • darkColorScheme() - Dark theme color scheme

Text Styles

Miuix provides a set of predefined text styles to maintain consistency in text throughout the application:

Style NameUsage
mainMain text
title1Large title (32sp)
title2Medium title (24sp)
title3Small title (20sp)
body1Body text (16sp)
body2Secondary body text (14sp)
buttonButton text (17sp)
footnote1Footnote (13sp)
footnote2Small footnote (11sp)

Using Text Styles

You can access the current theme's text styles via MiuixTheme.textStyles:

kotlin
Text(
    text = "This is a title",
    style = MiuixTheme.textStyles.title2
)

Text(
    text = "This is body content",
    style = MiuixTheme.textStyles.body1
)

Customizing the Theme

You can globally customize the Miuix theme by providing your own Colors and TextStyles instances:

kotlin
// Custom color scheme
val customColors = lightColorScheme(
    primary = Color(0xFF6200EE),
    onPrimary = Color.White,
    background = Color(0xFFF5F5F5),
    // Other colors...
)

// Custom text styles
val customTextStyles = defaultTextStyles(
    title1 = TextStyle(
        fontSize = 36.sp,
        fontWeight = FontWeight.Bold
    ),
    // Other text styles...
)

// Apply custom theme
MiuixTheme(
    colors = customColors,
    textStyles = customTextStyles
) {
    // Your application content
}

Follow to System Dark Mode

To automatically follow the system's dark mode switch, you should use the isSystemInDarkTheme() function:

kotlin
@Composable
fun MyApp() {
    val isDarkTheme = isSystemInDarkTheme()
    val colors = if (isDarkTheme) {
        darkColorScheme()
    } else {
        lightColorScheme()
    }
    
    MiuixTheme(colors = colors) {
        // Application content
    }
}

Released under the Apache-2.0 License