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

Android 12及以上设备android:windowBackground作为启动页失效问题排查

Android 12启动页显示应用Logo而非自定义图标的原因及解决方法

问题原因

Android 12(API 31)引入了全新的SplashScreen API,系统默认会采用应用的自适应图标作为启动屏内容,原本通过android:windowBackground自定义启动页的方式会被系统默认的启动屏逻辑覆盖,因此自定义启动图无法正常显示,取而代之的是应用Logo。

解决方案

方案一:适配Android 12的SplashScreen API(推荐)

这种方式符合Android官方设计规范,同时兼容低版本设备:

  1. 保留原有的splash_image作为低版本的启动页资源。
  2. 在res/values/styles.xml(或专门创建res/values-v31/styles.xml针对Android 12+)中更新LoadingScreen主题,添加SplashScreen相关属性:
<style name="LoadingScreen" parent="DarkMode">
    <!-- 兼容Android 11及以下版本 -->
    <item name="android:windowBackground">@drawable/splash_image</item>
    <item name="android:statusBarColor">@color/papaya_orange</item>
    
    <!-- Android 12+ 启动屏配置 -->
    <item name="android:windowSplashScreenBackground">@color/papaya_orange</item>
    <item name="android:windowSplashScreenAnimatedIcon">@drawable/logo_transparant_white_loading_screen</item>
    <!-- 若不需要启动动画,设置时长为0 -->
    <item name="android:windowSplashScreenAnimationDuration">0</item>
</style>
  1. (可选)在MainActivity的onCreate方法中处理启动屏退出逻辑:
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
        splashScreen.setOnExitAnimationListener { splashScreenView ->
            splashScreenView.remove()
        }
    }
    setContentView(R.layout.activity_main)
}

方案二:关闭Android 12默认启动屏(不推荐)

如果想继续使用旧的windowBackground方式,可在Android 12的主题中关闭系统默认启动屏:

<style name="LoadingScreen" parent="DarkMode">
    <item name="android:windowBackground">@drawable/splash_image</item>
    <item name="android:statusBarColor">@color/papaya_orange</item>
    <!-- 关闭Android 12默认启动屏 -->
    <item name="android:windowSplashScreenEnabled">false</item>
</style>

注意:该方式不符合Android 12及后续版本的设计规范,可能在未来系统版本中失效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 16:27:23