Android Night Mode without CarModeEnabled

这一生的挚爱 提交于 2019-12-04 19:25:42

问题


So I made separate xmls for night mode and kept them in layout-night.

Then I switch to night mode:

UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
    if (nightMode) {
        uiManager.enableCarMode(0);
        uiManager.setNightMode(UiModeManager.MODE_NIGHT_YES);
    } else {
        uiManager.disableCarMode(0);
        uiManager.setNightMode(UiModeManager.MODE_NIGHT_NO);
    }

Is it possible to set night mode without enabling car mode?

or for that matter possible to use layout-night, values-night etc folders without using setNightMode()?


回答1:


With 23.2.0(and higher) appcompat library it is possible with:

AppCompatDelegate.setDefaultNightMode

Here you will find example.




回答2:


NO, According to docs setNightMode() "Changes to the night mode are only effective when the car or desk mode is enabled on a device."

http://developer.android.com/reference/android/app/UiModeManager.html#setNightMode(int)

Check : https://stackoverflow.com/a/23123791/28557



来源:https://stackoverflow.com/questions/18825544/android-night-mode-without-carmodeenabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!