Skip to content

Android 12+: let the splash follow the app's light/dark setting - #837

Open
ahamsel wants to merge 2 commits into
jonbhanson:masterfrom
ahamsel:android12-app-theme-splash
Open

ahamsel wants to merge 2 commits into
jonbhanson:masterfrom
ahamsel:android12-app-theme-splash

Conversation

@ahamsel

@ahamsel ahamsel commented Nov 13, 2026 •

Copy link
Copy Markdown

Closes #542

My app lets people pick Light or Dark, and on Android 12+ the splash always followed the phone instead. So with the phone in dark mode and the app on Light you'd get a dark splash. Android has SplashScreen.setSplashScreenTheme for this, but there was no theme to pass it, since LaunchTheme has a light and a night version.

This adds an opt-in app_theme_styles: true under android_12. It generates NativeSplashLight and NativeSplashDark in values-v31/styles.xml only, so they don't change with the phone's theme. If image_dark is different from image, it also writes copies of the images with no night version, because a drawable that has one still gets picked by the phone's theme, even from a fixed style. Same for branding_dark. Turning it off or running remove cleans everything up. Without the option nothing changes: I diffed the generated res folder on master and on this branch with every android_12 key set, and it's identical.

The package dropped its native code in #828, so I didn't add a plugin back. The README has a short Kotlin method channel for MainActivity and the Dart call instead. Happy to turn it into a Dart API if you'd rather have that.

Worth knowing: UiModeManager.setApplicationNightMode isn't enough on its own. On my Galaxy S20 FE (Android 13) the splash still followed the phone when I opened the app from its icon. setSplashScreenTheme works either way. Android saves the style by name, so NativeSplashLight and NativeSplashDark shouldn't be renamed later.

I added tests in test/android_test.dart and checked it on the S20 FE in dark mode with a test app using the README code, red icon for light and green for dark. Left to right: nothing picked, Light, System, and Light pointed at the night drawable instead of the copy (wrong icon, which is why the copies are there).

Splash on a Galaxy S20 FE in dark mode: no choice saved, Light picked, System picked, Light with the night drawable

flutter analyze shows 12 XmlName deprecation infos with xml 7.1.0, but those are on master too.

…tting

On Android 12+ the splash follows the phone's dark mode. With
`app_theme_styles: true` in the android_12 section, the generator adds
NativeSplashLight and NativeSplashDark to the non-night v31 styles file.
An app can pass them to SplashScreen.setSplashScreenTheme so the splash
follows its own theme setting.

A drawable with a night variant still follows the phone's theme inside a
fixed style, so when image_dark or branding_dark differs from the light
one, the styles use copies written only to non-night folders. Turning the
option off, or running remove, deletes the styles and the copies.

LaunchTheme's Android 12 items now go through the same helper; generated
output for existing configs is unchanged.

Refs jonbhanson#542
Adds a README section with the method channel an app adds to
MainActivity to call SplashScreen.setSplashScreenTheme, notes that
UiModeManager.setApplicationNightMode is not enough on Samsung's
launcher, and updates the FAQ on basing light/dark on app settings.

Closes jonbhanson#542
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show a light/dark splash screen if the app have forced light/dark theme saved in cache.

1 participant