Android 5.1中Jetpack Compose SplashScreen图标不显示求助
解决Android 5.1上SplashScreen API图标不显示的问题
核心问题分析
Jetpack SplashScreen API在API 31以下设备上的兼容逻辑与高版本存在差异,再加上配置细节的疏漏,导致图标无法加载。
具体修复步骤
1. 修正主题的图标属性
API 31以下设备不支持windowSplashScreenAnimatedIcon属性,需替换为兼容低版本的windowSplashScreenIcon,同时移除资源名末尾的空格(空格会导致资源找不到):
<style name="Theme.MySplashScreen" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@color/black</item> <!-- 替换为低版本兼容属性,移除资源名后的空格 --> <item name="windowSplashScreenIcon">@drawable/baseline_pause_24</item> <item name="postSplashScreenTheme">@style/Theme.AudioApp</item> </style>
2. 启用矢量图低版本兼容
Android 5.1默认不支持直接将矢量图作为启动图标,需在Module级build.gradle中添加配置:
android { defaultConfig { vectorDrawables.useSupportLibrary = true } }
同时可暂时移除矢量图的tint属性测试,排除颜色冲突问题。
3. 调整ViewModel状态监听逻辑
低版本下StateFlow的状态同步可能存在延迟,改用Compose更适配的MutableState:
class SplashScreenViewModel: ViewModel() { val isLoading = mutableStateOf(true) init { viewModelScope.launch { delay(800) isLoading.value = false } } }
MainActivity中保持原监听逻辑即可。
4. 修正Manifest主题配置
仅给启动Activity设置SplashScreen主题,Application主题改用常规主题避免冲突:
<application android:name=".MyApplication" ... android:theme="@style/Theme.AudioApp" tools:targetApi="31"> <activity android:name=".ui.activities.MainActivity" android:exported="true" android:theme="@style/Theme.MySplashScreen"> ... </activity> </application>
验证操作
清理项目缓存(Build -> Clean Project)后重新构建,在Android 5.1设备上运行测试。
内容的提问来源于stack exchange,提问作者Fatima Jamal
相关产品推荐
相关产品推荐

