Skip to content

Instantly share code, notes, and snippets.

@truedem
Created June 26, 2020 20:39
Show Gist options
  • Save truedem/a1690e22f0a1c423c49e5c984a382a99 to your computer and use it in GitHub Desktop.
Save truedem/a1690e22f0a1c423c49e5c984a382a99 to your computer and use it in GitHub Desktop.
Kotlin one-liner to check if Android device is in day or night mode?
// usage in fragment: val color = if(requireContext().isDarkThemeOn()) Color.DKGRAY else Color.WHITE
// source: https://stackoverflow.com/questions/55787035/is-there-an-api-to-detect-which-theme-the-os-is-using-dark-or-light-or-other
fun Context.isDarkThemeOn() = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment