Nucleus
OS integrationTheme

System accent color

Read the user's OS accent color and high-contrast setting as Compose state that follows system changes.

View as Markdown

system-color reads the user's accent color and high-contrast setting on macOS, Windows and Linux. Both are composables that recompose when the user changes them in the system settings.

system-colormacOSWindowsLinuxGradle plugin: Not neededWindow runtime: Not needed

Switching System Settings to Light, then through green, pink and orange accents: the app follows each change live

Add the dependency

build.gradle.kts
dependencies {
    implementation("dev.nucleusframework:nucleus.system-color:3.0.0")
}

Read the accent color

import dev.nucleusframework.systemcolor.systemAccentColor

@Composable
fun App() {
    val accent = systemAccentColor()
    val scheme = if (accent != null) darkColorScheme(primary = accent) else darkColorScheme()

    MaterialTheme(colorScheme = scheme) {
        // Recomposes when the user picks another accent.
    }
}

systemAccentColor() returns null when the OS does not report an accent, for example on a Linux desktop whose portal lacks the accent-color key. Fall back to your brand color.

Read the high-contrast setting

val highContrast = isSystemInHighContrast()
// Strengthen borders and contrast tokens when highContrast is true.

API reference

FunctionReturns
isSystemAccentColorSupported(): BooleanWhether the OS can report an accent color. Not composable, so you can call it anywhere
@Composable systemAccentColor(): Color?The current accent color, or null
@Composable isSystemInHighContrast(): BooleanWhether the OS runs in high-contrast mode

What's next

Was this page helpful?
Edit on GitHub

Last updated on