I have an app in which the user can choose between the default theme and a dark theme. The manifest applies
AppTheme to the
<application>, while each activity checks the relevant flag and uses
setTheme(AppTheme.Dark) if necessary.
This implementation works well for all my activities, but the preview window shown by the OS before the application launches uses the Manifest theme, i.e. the light one. So users get a sudden white screen before reaching the dark app.
Based on other SO answers, I gathered that the only customization we can do is to set a
windowBackground drawable for the window to use (and a
statusBarColor if needed).
Even though I have two different
windowBackground set for each theme, I can’t change the theme for the preview window since the
Application class seems to load after it, and setting theme there makes no difference.
I’d like to avoid disabling the preview since it adds a noticeable delay without much indication that the app is launching. Is there any solution to this? I’m considering having a dark color for both themes in the worst case, like the Reddit app does.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- primary and accent color attributes --> <item name="android:windowBackground">@color/activityBackgroundLight</item> </style> <style name="AppTheme.Dark" parent="AppTheme"> <!-- primary and accent color attributes --> <item name="android:windowBackground">@color/activityBackgroundDark</item> </style>
Note: While I’m using colors here, I’ve already tried with a gradient drawable and it doesn’t change anything.