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

Android 5.0/5.1设备SplashScreen API图标不显示问题求助

问题:Android 5.0/5.1设备上SplashScreen API无法显示图标

我正在使用SplashScreen API,其余功能均正常,但在Android 5.0和5.1设备上无法显示图标。已按照官方文档操作但问题仍未解决。

环境信息

SplashScreen API版本

implementation 'androidx.core:core-splashscreen:1.0.0'

Theme.xml

<style name="Theme.Splash" parent="Theme.SplashScreen.IconBackground">
        <item name="postSplashScreenTheme">@style/Theme.MyTheme</item>
</style>

MainActivity.kt

val splashScreen = installSplashScreen()

Manifest.xml

<application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:name=".CarApplication"
        android:theme="@style/Theme.Splash"
        tools:targetApi="31">
        <activity
            android:theme="@style/Theme.Splash"
            android:name=".presentation.MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
 </application>

效果对比

Android 11效果

Android 11显示正常的启动页

Android 5.0效果

Android 5.0无图标的启动页

解决方案

针对Android 5.x(API 21-22)的兼容性问题,可尝试以下方案:

  1. 添加低版本兼容的图标背景配置
    在Theme.Splash主题中补充低版本适配的窗口背景属性,因为Theme.SplashScreen.IconBackground在低版本设备上无法自动读取应用图标:

    <style name="Theme.Splash" parent="Theme.SplashScreen.IconBackground">
        <item name="postSplashScreenTheme">@style/Theme.MyTheme</item>
        <!-- 适配Android 5.x的窗口背景 -->
        <item name="android:windowBackground">@drawable/splash_compat_bg</item>
    </style>
    

    新建drawable/splash_compat_bg.xml,用图层列表模拟SplashScreen的图标居中样式:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- 与SplashScreen一致的背景色 -->
        <item android:drawable="@color/splash_bg_color"/>
        <!-- 居中显示的应用图标 -->
        <item>
            <bitmap
                android:gravity="center"
                android:src="@mipmap/ic_launcher"/>
        </item>
    </layer-list>
    
  2. 升级SplashScreen库版本
    当前使用的1.0.0版本存在低版本适配缺陷,升级到最新稳定版(如1.0.1及以上)可修复部分兼容性问题:

    implementation 'androidx.core:core-splashscreen:1.0.1'
    
  3. 为低版本单独创建启动主题
    在res/values-v21/styles.xml中定义专属的低版本启动主题,避免高版本主题的兼容性冲突:

    <style name="Theme.Splash" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_compat_bg</item>
        <item name="postSplashScreenTheme">@style/Theme.MyTheme</item>
    </style>
    

    高版本设备会自动使用res/values/styles.xml中的原主题,低版本则加载这个适配主题。

内容的提问来源于stack exchange,提问作者U. Manzoor

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 16:48:25