Background
I know there is a new feature on Android Q to finally support dark theme (wrote here about detecting it).
I also know that there is "Night Light" feature (here) that makes the screen become more yellow-ish.
Supporting the theme choosing manually is something I've done for years (using simply setTheme on Activity's onCreate's first line of code), but I want to know if there is something automatic that will allow me to set it even before the app really starts, in the splash screen.
The problem
It seems a very old feature (since API 8!) has existed on Android for a very long time, of having "night" qualifier in the resources, and I never even tried it.
Sadly, because "dark theme" and night-related stuff are now more often talked about as the new features (here for example), I can't find what's the old one all about.
Looking at some articles and documentations, though, it seems it's almost completely manual:
https://developer.android.com/reference/android/app/UiModeManager.html - says I can set it myself, including set it to be automatic. However, it seems it's related to being docked, and maybe even car-mode.
https://google-developer-training.github.io/android-developer-fundamentals-course-concepts/en/Unit%202/53_c_providing_resources_for_adaptive_layouts.html - Says I can set "night" as a qualifier, and there is a "night mode".
What I've tried
I tried to set the various themes accordingly:
res/drawable/splash.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:opacity="opaque" tools:ignore="UnusedAttribute">
<item android:gravity="fill">
<shape android:shape="rectangle">
<solid android:color="#fff"/>
</shape>
</item>
...
</layer-list>
res/drawable-v29/splash.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:opacity="opaque" tools:ignore="UnusedAttribute">
<item android:gravity="fill">
<shape android:shape="rectangle">
<solid android:color="?attr/colorSurface"/>
</shape>
</item>
...
</layer-list>
res/drawable-night/splash.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:opacity="opaque" tools:ignore="UnusedAttribute">
<item android:gravity="fill">
<shape android:shape="rectangle">
<solid android:color="#000"/>
</shape>
</item>
...
</layer-list>
manifest
res/values/themes.xml
<style name="AppTheme_splash" parent="@style/Theme.MaterialComponents.DayNight">
<item name="android:windowBackground">@drawable/splash</item>
</style>
res/values-v26/themes.xml
<style name="AppTheme_splash" parent="@style/Theme.MaterialComponents.DayNight">
<item name="android:windowSplashscreenContent">@drawable/splash</item>
</style>
I tried to remove the android:windowBackground
and android:windowSplashscreenContent
, trying to see if it's automatic , but it didn't help.
The questions
Basically I just want to know about night-mode and if I can use it for the splash screen:
When do the "night mode" that Android supports for so long kick in?
Is it a os-global mode? Does the user control it?
Is it automatic? Or completely manual by the current app?
Does the mode stay later, even if I set it manually by the app and the app is killed ?
Is it possible to set the theme of the application (meaning for the splash screen) to use this, so that while night-mode is enabled, it will use it to have a dark background?
Is my code correct for this?