You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Splash Screen夜间模式下背景颜色不更新问题求助

Fixing Dark Mode Issue for XML-Based Splash Screen

Hey there! Let's tackle why your splash screen is stuck on white even when dark mode is enabled. I've run into this exact issue before, so here's what to check and fix:

1. Make Sure Your Color Resource Has Dark Mode Support

The most common culprit here is that your @color/mainBG doesn't have a corresponding dark variant.

  • In res/values/colors.xml (light mode):
    <color name="mainBG">#FFFFFF</color>
    
  • You must create a res/values-night/colors.xml file for dark mode, with the dark version of the color:
    <color name="mainBG">#1A1A1A</color> <!-- Or your preferred dark background color -->
    

If this file is missing or the color isn't defined here, the system will fall back to the light mode color, hence the white background in dark mode.

2. Verify Your Splash Screen Theme Inheritance

Your SplashScreen theme's parent (Theme.StookPTU) might not be set up to support day/night switching. Let's adjust that:

Update your theme in res/themes.xml and res/themes.xml(night) to inherit from a day-night compatible parent, like Theme.MaterialComponents.DayNight.NoActionBar (or whatever fits your app's base theme):

<!-- res/themes.xml (light mode) -->
<style name="SplashScreen" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_screenbg</item>
    <!-- Add any other splash screen-specific styles here -->
</style>

<!-- res/themes.xml(night) (dark mode) -->
<style name="SplashScreen" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_screenbg</item>
    <!-- Keep this consistent since the drawable uses a theme-aware color -->
</style>

This ensures the theme respects the system's dark mode setting and loads the correct color resources.

3. Double-Check Your Manifest & App Dark Mode State

  • Confirm your AndroidManifest.xml is correctly using the SplashScreen theme for your launch activity (your existing code looks good here, but it never hurts to double-check!).
  • Make sure dark mode is actually enabled: Either toggle it in your device's system settings, or if your app has an in-app dark mode toggle, ensure it's triggering the theme change properly.
  • Sometimes cached resources can cause issues—try clearing your app's cache and restarting it to rule out stale resources.

4. Bonus: Check for Overrides

If you're targeting Android 10 (API 29+) or higher, ensure your theme doesn't have android:forceDarkAllowed="false" set, which would prevent dark mode from applying. You can explicitly set it to true if needed:

<item name="android:forceDarkAllowed">true</item>

Once you've made these changes, your splash screen should correctly switch between light and dark backgrounds based on the system (or app) mode.

内容的提问来源于stack exchange,提问作者Daksh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 15:33:14