Android 12 启动页图标背景颜色修改无效求助
Android 12 启动页图标背景颜色修改无效求助
兄弟,我看你这问题跟我之前踩过的坑一模一样!先仔细瞅了眼你贴的values-v32/styles.xml代码,咱一步步来排查解决哈。
先把你提供的代码贴出来方便参考:
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off --> <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar"> <item name="android:forceDarkAllowed">false</item> <item name="android:windowFullscreen">false</item> <item name="android:windowDrawsSystemBarBackgrounds">false</item> <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> <item name="android:windowSplashScreenBackground">#0f0f0f</item> <item name="android:windowSplashScreenIconBackgroundColor">#0f0f0f</item> </style> <!-- Theme applied to the Android Window as soon as the process has started.--> <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar"> <item name="android:windowBackground">?android:colorBackground</item> </style> </resources>
问题根源
你设置的android:windowSplashScreenIconBackgroundColor不生效,核心原因是你的LaunchTheme父主题选错了!
@android:style/Theme.Black.NoTitleBar是Android旧版的非Material风格主题,它根本不支持Android 12新增的SplashScreen相关属性,所以你写的这些配置系统根本不会识别。
解决方案
咱按步骤来改:
- 替换LaunchTheme的父主题
把父主题换成支持SplashScreen的系统默认Material风格主题,比如:
<style name="LaunchTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar"> <!-- 保留你原来的所有配置项 --> <item name="android:forceDarkAllowed">false</item> <item name="android:windowFullscreen">false</item> <item name="android:windowDrawsSystemBarBackgrounds">false</item> <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> <item name="android:windowSplashScreenBackground">#0f0f0f</item> <item name="android:windowSplashScreenIconBackgroundColor">#0f0f0f</item> </style>
如果你项目里依赖了Material Components库,也可以用Theme.MaterialComponents.Light.NoActionBar作为父主题,效果是一样的。
- 确认启动Activity的主题配置
打开AndroidManifest.xml,找到你的启动Activity,确保它的android:theme属性设置的是@style/LaunchTheme,而不是NormalTheme,因为启动页的主题必须在进程启动时就应用:
<activity android:name=".MainActivity" android:exported="true" android:theme="@style/LaunchTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
- 清理缓存重新编译
这步超重要!Android Studio经常会缓存旧的资源文件,导致你改了配置也不生效。建议先点击Build -> Clean Project,然后再Rebuild Project,最后重新安装到设备上。
额外提醒
如果你是用Flutter、React Native这类跨平台框架开发的,还要注意框架自带的启动页配置会不会覆盖你的设置,比如Flutter的flutter_launcher_icons插件可能会自动生成启动图标背景,这时候你需要同步调整插件的配置。
内容来源于stack exchange




