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

Android 12 Splash Screen API问题:PNG图标设为windowSplashScreenAnimatedIcon后拉伸如何调整

解决Android 12 Splash Screen API中PNG图标拉伸的问题

核心原因

Android 12的Splash Screen API会将windowSplashScreenAnimatedIcon设置的图标适配到固定的启动屏图标区域,PNG如果尺寸不匹配或未适配多dpi,就会出现拉伸变形。

具体解决方法

  • 适配多dpi目录
    按照Android官方启动屏图标尺寸规范,制作对应dpi的PNG图标,放入对应的drawable目录:

    • mdpi: 48×48像素
    • hdpi: 72×72像素
    • xhdpi: 96×96像素
    • xxhdpi: 144×144像素
    • xxxhdpi: 192×192像素
      系统会根据设备dpi自动加载对应尺寸的图标,从根源避免拉伸。
  • 用LayerDrawable固定图标尺寸
    若不想制作多套图标,可创建xml drawable包裹PNG图标,强制设置尺寸并居中:

    1. 在res/drawable下创建splash_icon_wrapper.xml,内容如下:
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:drawable="@drawable/your_png_icon"
            android:width="96dp"
            android:height="96dp"
            android:gravity="center"/>
    </layer-list>
    
    1. 在主题中修改windowSplashScreenAnimatedIcon指向该xml文件:
    <style name="SplashTheme" parent="Theme.SplashScreen">
        <item name="windowSplashScreenAnimatedIcon">@drawable/splash_icon_wrapper</item>
        <!-- 其他启动屏相关属性 -->
    </style>
    

    图标会保持设置的96dp×96dp尺寸,居中显示,不会被拉伸。

  • 修改PNG图标本身
    给PNG图标添加透明空白边,让图标整体尺寸符合对应dpi规范(比如xhdpi下调整为96×96像素,图标内容居中),再放入对应drawable目录,系统加载时就不会拉伸图标内容。

内容的提问来源于stack exchange,提问作者Martin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 23:45:44