Android 8.0 启动图标适配

参考

  1. 和UI设计师商量下,将之前的logo分为前景与背景两张图.
  • 之前的logo图如下:
  • 现在需要将上图分离为前景与背景图如下:
  1. 鼠标焦点放在src目录上,按下Windows:Ctrl+Shift+A 或者 Mac:command+shft+A 快捷键,输入Image Asset.打开Configure Image Asset窗口,如下:

    配置时候,Preview中有个圆圈表示的是范围,在这个范围内展示logo的主要内容,范围之外的到时候在手机上展示的时候会被自动裁剪掉.Preview区域的Legacy Icon图标表示的是在6.0系统上启动图标呈现出来的样子.
  2. 剩下的就是确认创建启动图标,在mipmap-anydpi-v26文件夹中会看到两个xml文件,如下:
ic_launcher.xml
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@mipmap/ic_launcher_background"/>
    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
ic_launcher_round.xml
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@mipmap/ic_launcher_background"/>
    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

ic_launcher_backgroundic_launcher_foreground图片是由第二步配置生成的,然后还要配置清单文件中的android:icon="@mipmap/ic_launcher",到这里就成功了.
4. 问题

  • android:roundIcon="@mipmap/ic_launcher_round": 这个是Android 7.1系统过度版本才有,无需关心.
  • 其他布局要使用启动图标的话建议使用@mipmap/ic_launcher,他会根据不同版本的系统呈现出来不同的样式,效果就是Configure Image Asset窗口里预览的那些样式.有些国产机在其他布局中使用@mipmap/ic_launcher就算是8.0以上系统,呈现的样式还是6.0系统里的图标.不过我用国外手机也测试过,一些国外的手机像SM-J330G,HUAWEI ATU-L22,OPPO CPH1803这几个机型是可以在其他布局中做到自动适配的.

猜你喜欢

转载自blog.csdn.net/MoLiao2046/article/details/107144227