isSystemInDarkTheme

Functions summary

Boolean

Returns whether the operating system is in dark theme.

Cmn

Functions

isSystemInDarkTheme

@Composable
fun isSystemInDarkTheme(): Boolean

Returns whether the operating system is in dark theme.

This function should be used to help build responsive UIs that follow the system setting, to avoid harsh contrast changes when switching between applications.

It is recommended for this to be used at the top level of the application, to create theming objects such as a set of colors that can be provided through the hierarchy. This way, screens and components don't need to be aware of the system theme setting, they just consume properties from the theming object. This also makes it easier to support user-defined overrides, such as forcing light / dark theme regardless of the system setting.

import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

val dark = isSystemInDarkTheme()
val color = if (dark) Color.White else Color.Black
Box { Box(Modifier.size(50.dp).background(color = color)) }
Returns
Boolean

true if the system is considered to be in 'dark theme'.