【发布时间】:2021-04-06 10:43:04
【问题描述】:
我看到了很多关于在堆栈溢出时检测暗模式的问题,例如 this one,并访问了许多中型博客,例如 How to know when you’re using dark mode programmatically 和 DayNight — Adding a dark theme to your app,他们都执行了这样的检查:
fun isNightModeEnabled(context: Context): Boolean =
context.resources.configuration.uiMode.and(UI_MODE_NIGHT_MASK) ==
UI_MODE_NIGHT_YES
这适用于任何手机,甚至是运行 Android One 的小米手机,但不适用于运行 MIUI 的小米智能手机。
对于运行 MIUI 的小米设备:
context.resources.configuration.uiMode = 17
和context.resources.configuration.uiMode.and(UI_MODE_NIGHT_MASK) = 16
与 UI_MODE_NIGHT_YES (32) 相比,在启用或禁用暗模式时总是返回 false。
是否真的可以检测到此类设备已强制使用暗模式?
【问题讨论】:
标签: android xiaomi miui android-darkmode