如何将Vector Drawable适配Android Splash Screen API要求?
适配Android Splash Screen API的无背景图标(已有Vector Drawable)
首先明确官方要求:
无背景应用图标:尺寸必须为288×288 dp,且适配直径192 dp的圆形区域
给你一步步来,都是新手能跟着操作的步骤:
1. 修改Vector图标的画布尺寸
找到你存放Vector Drawable的文件(一般在res/drawable/文件夹下),打开后修改根标签<vector>的属性:
把width和height改成288dp,viewportWidth和viewportHeight也设为288——这样画布大小就符合要求了。示例代码:
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="288dp" android:height="288dp" android:viewportWidth="288" android:viewportHeight="288"> <!-- 这里是你原来的图标路径代码 --> </vector>
2. 把图标内容限制在192dp的圆形区域里
288dp的画布,要让图标只在中间直径192dp的圆内显示,核心就是控制图标大小并居中:
- 用Android Studio可视化编辑器最省心:打开Vector文件,选中所有图标路径,用缩放工具调整大小,确保整个图标都在画布中心的192dp范围内(嫌麻烦可以临时画个直径192的圆当参考线,调完删掉就行)。
- 要是习惯手动改代码,就调整路径的
scaleX/scaleY属性,或者直接修改路径的坐标值,保证图标居中且整体大小不超过192dp。
3. 配置Splash Screen主题
在res/values/styles.xml(如果只针对Android 12+,也可以用res/values-v31/styles.xml)里,新建或修改Splash主题,指定这个图标:
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen"> <!-- 替换成你的Vector图标文件名 --> <item name="windowSplashScreenAnimatedIcon">@drawable/your_vector_icon</item> <!-- 无背景图标可以加个背景色,这里换成你想要的颜色 --> <item name="windowSplashScreenBackground">@color/splash_bg</item> <!-- 指定Splash结束后要切换到的App主题 --> <item name="postSplashScreenTheme">@style/Theme.YourAppName</item> </style>
4. 在Manifest里启用这个主题
打开AndroidManifest.xml,把<application>标签的android:theme改成刚才的Splash主题:
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/Theme.App.SplashScreen"> <!-- 你的Activity等内容 --> </application>
内容的提问来源于stack exchange,提问作者lanezalbryt
相关产品推荐
相关产品推荐

