Android 12及以上版本启动页图片不显示问题求助
解决Android 12+启动页图片不显示问题
问题描述
Android 12(API 31)及以上版本启动页仅能显示设置的背景色,配置的启动图片无法加载;Android 12以下版本显示正常。当前配置文件位于values-v31/styles.xml,代码如下:
<?xml version="1.0" encoding="utf-8" ?> <resources> <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar"> <item name="android:windowSplashScreenBackground">#000000</item> <item name="android:windowSplashScreenAnimatedIcon"> @drawable/splash </item> </style> </resources>
问题原因
- 主题父类不兼容:Android 12引入了全新的Splash Screen API,
Theme.Black.NoTitleBar这类旧主题未适配该API,无法正确解析windowSplashScreenAnimatedIcon属性。 - 图标资源类型不符合要求:
windowSplashScreenAnimatedIcon要求资源为VectorDrawable(矢量图)或AnimatedVectorDrawable(动画矢量图),普通png/jpg位图会被系统直接忽略。
解决方案
1. 替换主题父类
将LaunchTheme的父类改为Android 12+专属的Theme.SplashScreen,确保系统能识别启动页相关属性:
<style name="LaunchTheme" parent="@android:style/Theme.SplashScreen">
2. 调整图标资源
- 推荐方案:把png/jpg图片转换为VectorDrawable。可以使用Android Studio的
File > New > Vector Asset工具,选择本地图片导入生成矢量图。 - 兼容位图方案:如果必须使用位图,需额外添加
windowSplashScreenIconBackgroundColor属性,同时保证位图尺寸符合规范(建议112x112dp,不同密度目录下对应尺寸按比例调整):
<item name="android:windowSplashScreenIconBackgroundColor">#000000</item>
3. 完整配置示例
修改后的values-v31/styles.xml代码:
<?xml version="1.0" encoding="utf-8" ?> <resources> <style name="LaunchTheme" parent="@android:style/Theme.SplashScreen"> <!-- 启动页背景色 --> <item name="android:windowSplashScreenBackground">#000000</item> <!-- 启动页图标(矢量图/动画矢量图) --> <item name="android:windowSplashScreenAnimatedIcon">@drawable/splash</item> <!-- 若使用位图,需添加此属性设置图标背景色 --> <!-- <item name="android:windowSplashScreenIconBackgroundColor">#000000</item> --> <!-- 可选:设置启动页动画时长 --> <!-- <item name="android:windowSplashScreenAnimationDuration">1000</item> --> </style> </resources>
额外检查项
- 确认
@drawable/splash资源存在于项目的drawable目录下,资源名称无拼写错误 - 若使用动画矢量图,需确保AnimatedVectorDrawable的xml配置正确,无语法错误
内容的提问来源于stack exchange,提问作者steind.VY
相关产品推荐
相关产品推荐

