I want to implement night mode in my APP (manual switch for day and night mode), and I found out that I can use UiModeManager.setNightMode() and add some resources like values-night and drawable-night to archive it.
In the document before setNightMode() we need enableCarMode() .
Using the code as shown below may work, but a problem has occurred.
UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE); if (isNightMode) { uiManager.enableCarMode(0); uiManager.setNightMode(UiModeManager.MODE_NIGHT_YES); } else { uiManager.disableCarMode(0); uiManager.setNightMode(UiModeManager.MODE_NIGHT_NO); }
It displays a notification allowing the user to exit vehicle mode.

Do you have an idea to disable this notification?
Or it just means that this is not the best way to implement Android night mode. And turning on car mode will lead to any weird differences from my APP or my phone?
PS: I wonder why we need to turn on car mode before setting night mode. Is there any deep thought in this?
PPS: I already know that I can change the theme to switch between day and night mode. It should call this.recreate() and makes the screen flicker for a second.
PPPS: If UiModeManager.setNightMode and change theme are not the best way to implement night mode, what choice do I have?
Edit:
Method 1: UiModeManager.setNightMode

Method 2: change theme

Change again:
I think my idea was wrong. Unable to turn off notification, but enable car mode.
All I want is to implement night mode, for example, method 1, without setting something like desktop or car mode, without showing flicker.
Finally
Using UiModeManager.setNightMode and turning on car mode is not the best way to implement night mode. Because it affects Android 5.0 and above.
When the car mode is on and the APP is running, I pressed the button at home, something strange happened (Test in nexus 7 Android 5.1.1). As the picture below:
Launch Android Auto
Find the Android Auto button on your car's display to get started

Unfortunately, UiModeManager.setNightMode cannot be used if car mode is not required.
With the exception of car mode, this result is ideal, and for developers, it can simply make several folders such as drawable-night and values-night without changing the code too large. While the mode is changed, it sends a broadcast and switches the system configuration to the corresponding user interface mode.
Although there are so many advantages, this is the wrong way to night mode.
I still wonder why the car and night mode go so close together.