Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Latest commit

 

History

History
12 lines (9 loc) · 727 Bytes

File metadata and controls

12 lines (9 loc) · 727 Bytes

Dark mode - Android

On Android, you can detect dark mode by checking if the uiMode configuration contains UI_MODE_NIGHT_MASK.

By adding -night resources to your project you can let Android automatically pick the right resources. For example, add a colors.xml file inside a values-night folder to specify night mode colors.

fun Context.isInNightMode(): Boolean {
    val nightModeFlags = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
    return nightModeFlags == Configuration.UI_MODE_NIGHT_YES
}