如何在Android12及以上禁用系统启动页?解决双启动页警告
解决方案:Android 12+ 关闭系统默认启动页(保留自定义启动页)
核心方案:使用Android 12+专属主题属性禁用系统启动页
直接用android:windowSplashScreenEnabled属性关闭系统默认启动页,同时保持窗口背景不透明,避免跳转时的视觉问题:
- 创建Android 12+专属主题
在res/values-v31/styles.xml中添加以下主题(继承你应用的基础主题):
<style name="Theme.App.Splash" parent="Theme.App.Base"> <!-- 禁用Android 12+系统默认启动页 --> <item name="android:windowSplashScreenEnabled">false</item> <!-- 设置和自定义启动页一致的背景,确保视觉连贯 --> <item name="android:windowBackground">@drawable/your_custom_splash_bg</item> <!-- 移除之前设置的透明属性,避免跳转时的透明问题 --> <item name="android:windowIsTranslucent">false</item> </style>
- 为自定义启动页Activity指定该主题
在AndroidManifest.xml中,给你的自定义启动页Activity绑定上述主题:
<activity android:name=".YourCustomSplashActivity" android:theme="@style/Theme.App.Splash"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
为什么之前的方案无效?
- 你尝试的
android:windowIsTranslucent="true"虽然能禁用系统启动页,但会让Activity窗口透明,导致跳转时出现空白/透明背景的问题。 windowSplashScreenEnabled是Android 12(API 31)新增的专属属性,专门用于控制是否显示系统默认启动页,不会影响窗口的不透明度,完美适配你的需求。
额外注意事项
- 确保自定义启动页Activity的布局背景和
windowBackground设置的资源一致,避免启动瞬间出现视觉断层。 - 如果自定义启动页需要处理网络请求或弹窗,务必在所有异步操作完成后再执行页面跳转,防止系统启动页消失后出现长时间空白。
内容的提问来源于stack exchange,提问作者user24467243
相关产品推荐
相关产品推荐

