Android SplashScreen Logo显示为纯圆形而非圆角正方形如何修复?
问题修复方案
你遇到的核心问题是Android 12及以上版本的启动页系统会自动将图标裁剪为圆形/圆角样式,导致你的正方形矢量图被裁剪成圆形。以下是两种可行的修复方案:
方案1:适配Android 12+启动页规范(推荐)
针对不同系统版本配置专属启动页主题,避免系统自动裁剪:
- 在
res/values/styles.xml中配置低版本(Android 11及以下)启动页:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> <item name="android:windowBackground">@drawable/splash_layer_list</item> </style>
- 在
res/values-v31/styles.xml中配置Android 12+启动页:
<style name="SplashTheme" parent="Theme.SplashScreen"> <!-- 启动页背景色 --> <item name="android:windowSplashScreenBackground">@color/Accent_900</item> <!-- 设置你的矢量图标,系统不会对这个图标做自动裁剪 --> <item name="android:windowSplashScreenAnimatedIcon">@drawable/b4w_logo_splash</item> <!-- 图标背景设为透明,避免额外色块 --> <item name="android:windowSplashScreenIconBackgroundColor">@color/transparent</item> <!-- 全屏显示启动页 --> <item name="android:windowFullscreen">true</item> </style>
方案2:修改Layer List结构
如果要继续使用Layer List适配全版本,通过限制图标尺寸避免系统裁剪:
修改你的splash_layer_list.xml文件:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/Accent_900"/> <!-- 给图标item指定固定宽高并居中,防止被拉伸或裁剪 --> <item android:width="171dp" android:height="171dp" android:gravity="center"> <android.graphics.drawable.VectorDrawable android:drawable="@drawable/b4w_logo_splash"/> </item> </layer-list>
或者使用inset来控制图标与屏幕边缘的间距,间接限制尺寸:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/Accent_900"/> <item> <inset android:insetLeft="40dp" android:insetRight="40dp" android:insetTop="40dp" android:insetBottom="40dp"> <android.graphics.drawable.VectorDrawable android:drawable="@drawable/b4w_logo_splash"/> </inset> </item> </layer-list>
额外提示
- 确保你的矢量图
b4w_logo_splash.xml中width/height与viewportWidth/viewportHeight比例一致,避免图标变形 - 推荐使用AndroidX的
SplashScreen库(依赖androidx.core:core-splashscreen:1.0.1),可以更便捷地实现全版本启动页的统一适配
内容的提问来源于stack exchange,提问作者Albert Buigues
相关产品推荐
相关产品推荐

