Created
June 26, 2020 20:39
-
-
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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