Android Core Splashscreen API在深色模式下导致启动图标变黑问题求助
解决Android新Splashscreen API深色模式图标变黑的问题
我之前也踩过这个坑!新的Splashscreen API在深色模式下的图标显示确实有几个容易忽略的配置点,给你整理几个排查和解决方向:
1. 检查图标资源的深色模式适配
新Splashscreen API要求启动图标拆分前景层(icon_foreground)和背景层(icon_background),如果只在drawable目录放了一套资源,深色模式下系统可能自动反转颜色导致图标变黑。
- 务必在
res/drawable-night目录下提供对应的前景图标资源,颜色要适配深色背景(比如用浅色代替默认黑色); - 或者直接在矢量图标里引用主题属性,比如用
?attr/colorOnSurface,让系统根据当前主题自动切换颜色:
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="48dp" android:height="48dp" android:viewportWidth="48" android:viewportHeight="48" android:tint="?attr/colorOnSurface"> <path android:fillColor="@android:color/white" android:pathData="..."/> </vector>
2. 核对Splashscreen主题的配置
确保你的启动页主题正确继承Theme.SplashScreen,并且关键属性适配深色模式:
- 在
values/styles.xml中配置基础主题:
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen"> <item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash_foreground</item> <item name="windowSplashScreenIconBackgroundColor">?attr/colorPrimary</item> <item name="postSplashScreenTheme">@style/Theme.App</item> </style>
- 在
values-night/styles.xml中对应调整背景色,保证前景图标和背景有足够对比度:
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen"> <item name="windowSplashScreenIconBackgroundColor">?attr/colorPrimaryDark</item> </style>
3. 关闭系统自动颜色反转(可选)
如果以上配置都没问题但还是变黑,可能是系统强制反转了图标颜色。可以在Splash主题中添加属性禁用这个行为:
<item name="android:forceDarkAllowed">false</item>
注意:这个属性仅针对Android 10及以上版本生效,需要权衡是否影响其他深色模式适配逻辑。
4. 清理缓存并重新构建
有时候旧的资源缓存会导致显示异常,建议:
- 卸载应用后重新安装;
- 在Android Studio中执行
Build > Clean Project+Rebuild Project,确保新资源被正确打包。
内容的提问来源于stack exchange,提问作者Abdullah
相关产品推荐
相关产品推荐

