OS integrationTheme
System accent color
Read the user's OS accent color and high-contrast setting as Compose state that follows system changes.
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-colorGradle plugin: Not neededWindow runtime: Not needed
Add the dependency
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
| Function | Returns |
|---|---|
isSystemAccentColorSupported(): Boolean | Whether 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(): Boolean | Whether the OS runs in high-contrast mode |
What's next
- Dark mode detector: combine the accent with the system theme.
- Accessibility: expose your UI to screen readers.
- Toolkits: native window looks for each OS.
Was this page helpful?
Edit on GitHub
Last updated on