Skip to content

Fix splashscreen theme not updating after theme change (#633)#2058

Closed
shaominngqing wants to merge 2 commits intoandroid:mainfrom
shaominngqing:fix/splashscreen-theme-633
Closed

Fix splashscreen theme not updating after theme change (#633)#2058
shaominngqing wants to merge 2 commits intoandroid:mainfrom
shaominngqing:fix/splashscreen-theme-633

Conversation

@shaominngqing
Copy link

Summary

This PR fixes the issue where the splash screen doesn't reflect the user's dark theme preference when the app is cold-started after changing the theme setting.

Problem

When a user changes the theme from the app settings (e.g., from light to dark), the preference is saved but AppCompatDelegate.setDefaultNightMode() is not called. As a result, on the next cold start, the splash screen still uses the old theme (light) and then switches to the app's new theme (dark), causing an unpleasant flash.

Solution

This PR applies AppCompatDelegate.setDefaultNightMode() in two places:

  1. SettingsViewModel.updateDarkThemeConfig(): Immediately apply the night mode when the user changes the setting
  2. MainActivity.onCreate(): Apply the saved theme preference on app startup to ensure consistency

This ensures the system-level night mode is synchronized with the user's preference, making the splash screen display correctly from the start.

Testing

Manual testing:

  1. Set device to light mode
  2. Open the app and change theme to dark in settings
  3. Force close the app
  4. Cold start the app
  5. ✅ Splash screen now shows in dark theme (previously showed light)

Changes

  • SettingsViewModel.kt: Added AppCompatDelegate.setDefaultNightMode() call
  • MainActivity.kt: Added startup logic to apply saved theme config

Reference

Fixes #633

@google-cla
Copy link

google-cla bot commented Feb 3, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link

Summary of Changes

Hello @shaominngqing, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a user experience inconsistency where the app's splash screen would briefly display with an incorrect theme (e.g., light mode) before switching to the user's preferred dark theme during a cold start. The changes ensure that the system-level theme is synchronized with the user's settings both immediately upon change and during initial application launch, providing a seamless visual experience from the very beginning.

Highlights

  • Problem Addressed: Fixed an issue where the splash screen did not correctly reflect the user's dark theme preference on cold app starts, leading to a visual flicker before the main app theme loaded.
  • Immediate Theme Application: Modified SettingsViewModel.updateDarkThemeConfig() to immediately apply the selected night mode using AppCompatDelegate.setDefaultNightMode() when the user changes the theme setting.
  • Startup Theme Synchronization: Implemented logic in MainActivity.onCreate() to read the saved theme preference and apply it via AppCompatDelegate.setDefaultNightMode() during app startup, ensuring the splash screen uses the correct theme from the very beginning.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt
    • Imported AppCompatDelegate and DarkThemeConfig to support theme management.
    • Added a lifecycleScope.launch block within onCreate to observe the viewModel.uiState and dynamically apply the appropriate AppCompatDelegate.setDefaultNightMode() based on the user's darkThemeConfig during app startup.
  • feature/settings/impl/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/settings/impl/SettingsViewModel.kt
    • Imported AppCompatDelegate to enable programmatic theme control.
    • Added a call to AppCompatDelegate.setDefaultNightMode() within the updateDarkThemeConfig function to instantly apply the chosen theme setting across the application.
Activity
  • The author, shaominngqing, has provided a comprehensive description detailing the problem, proposed solution, testing steps, and specific file changes.
  • No further review comments or activity have been recorded in the provided context.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves the splash screen theme inconsistency by ensuring that the AppCompatDelegate.setDefaultNightMode() is applied both when the user changes the theme setting in SettingsViewModel and during the app's cold startup in MainActivity. This dual approach guarantees that the splash screen correctly reflects the user's preferred theme, eliminating the unpleasant flash previously observed. The changes align well with the problem description and proposed solution.

@shaominngqing shaominngqing force-pushed the fix/splashscreen-theme-633 branch from 1ac6b0f to 4212fe5 Compare February 3, 2026 08:21
Apply AppCompatDelegate.setDefaultNightMode() when the user changes
the dark theme configuration to ensure the system-level night mode
is synchronized. This makes the splash screen display with the
correct theme on cold start.

Changes:
- SettingsViewModel: Apply night mode immediately when user changes theme
- MainActivity: Apply saved theme config on startup

Fixes android#633
- Use first() instead of collect() in MainActivity to avoid redundant
  calls when theme changes at runtime (since SettingsViewModel already
  handles that)
- Extract DarkThemeConfig to night mode mapping into extension functions
  to avoid code duplication and improve maintainability

Based on feedback from gemini-code-assist review
@shaominngqing shaominngqing force-pushed the fix/splashscreen-theme-633 branch from 4212fe5 to 02fa916 Compare February 3, 2026 11:19
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.

[Bug]: Splashscreen theme doesn't change after switching the color theme

1 participant

Comments