Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Night Mode without CarModeEnabled

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()?

like image 940
KetanJogani Avatar asked Sep 16 '13 10:09

KetanJogani


2 Answers

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

AppCompatDelegate.setDefaultNightMode

Here you will find example.

like image 79
Mateusz Pryczkowski Avatar answered Sep 20 '22 07:09

Mateusz Pryczkowski


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

like image 35
Vinayak Bevinakatti Avatar answered Sep 17 '22 07:09

Vinayak Bevinakatti