如何移除使用SplashScreen API时启动页图标周围的圆形蒙版
问题原因
Android 12及以上版本的SplashScreen API默认会对windowSplashScreenAnimatedIcon属性传入的资源施加自适应图标掩码约束,不管传入的是layer-list还是png位图,都会被强制裁剪为系统当前设定的图标形状(通常是圆形),同时自带形状边框,这是系统级的默认行为,和你的资源文件本身无关。
解决方案
方案1:隐藏圆形边框(快速适配,保留系统默认动画)
直接在启动主题中添加图标背景色属性,将其设置为和启动页背景完全一致的颜色,圆形边框会和背景融为一体,视觉上完全消失。
修改你的styles.xml中Theme.App.Starting的代码,新增一行配置:
<style name="Theme.App.Starting" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@color/sailor_blue</item> <item name="windowSplashScreenAnimatedIcon">@drawable/splash_screen_layer_list</item> <!-- 新增这行,图标背景色和启动页背景保持一致 --> <item name="windowSplashScreenIconBackgroundColor">@color/sailor_blue</item> <item name="postSplashScreenTheme">@style/Theme.SimpleCrypto.NoActionBar</item> </style>
方案2:完全禁用系统图标裁剪(适合异形logo)
如果你不想让logo被系统裁剪,可以把所有启动页视觉内容都放到背景属性中,直接隐藏系统默认的图标位:
- 把你现有的
splash_screen_layer_list.xml直接作为启动页背景传入 - 将
windowSplashScreenAnimatedIcon设置为透明
修改后的styles.xml代码如下:
<style name="Theme.App.Starting" parent="Theme.SplashScreen"> <!-- 直接传入你的layer-list作为整个启动页背景 --> <item name="windowSplashScreenBackground">@drawable/splash_screen_layer_list</item> <!-- 图标位设为透明,避免系统显示带边框的图标 --> <item name="windowSplashScreenAnimatedIcon">@android:color/transparent</item> <item name="postSplashScreenTheme">@style/Theme.SimpleCrypto.NoActionBar</item> </style>
两种方案都不需要修改你的Manifest和Activity代码,修改完成后清理缓存重新编译即可生效。
内容的提问来源于stack exchange,提问作者AniMike
相关产品推荐
相关产品推荐

