2017-05-24 412 views
2

我使用的是内置的白天/夜间模式功能机器人会和我想的选项添加到我的应用程序的AppCompatDelegate.MODE_NIGHT_AUTOAndroid的 - 如何检测,如果夜间模式是使用AppCompatDelegate.MODE_NIGHT_AUTO

我当上米有一个问题,虽然因为我的应用程序需要某些东西以编程方式着色,我无法弄清楚如何检查应用程序认为自己在夜间或白天模式。没有这个,我不能设置一个标志来选择正确的颜色。

调用AppCompatDelegate.getDefaultNightMode()只是返回无用的AppCompatDelegate.MODE_NIGHT_AUTO。

我没有看到任何会告诉我的东西,但肯定有东西吗?

+0

的可能的复制[如何获得AppCompatDelegate当前的模式下,如果默认为自动(https://stackoverflow.com/questions/41391404/how-to-get-appcompatdelegate-current-mode-if-default- is-auto) – StarWind0

回答

1
int nightModeFlags = 
    getContext().getResources().getConfiguration().uiMode & 
    Configuration.UI_MODE_NIGHT_MASK; 
switch (nightModeFlags) { 
    case Configuration.UI_MODE_NIGHT_YES: 
    case Configuration.UI_MODE_NIGHT_NO: 
    case Configuration.UI_MODE_NIGHT_UNDEFINED: 
} 
+0

谢谢,这个伎俩。我开始沿着检查颜色字符串值的路线查看它来自哪个资源文件,但是这样更好! – Ben987654

+0

请引用你的来源。 https://stackoverflow.com/questions/41391404/how-to-get-appcompatdelegate-current-mode-if-default-is-auto – StarWind0

+1

@ StarWind0我没有找到任何其他答案;这个答案纯粹来自API文档。 – ephemient