- 和UI設計師商量下,將之前的logo分爲前景與背景兩張圖.
- 之前的logo圖如下:
- 現在需要將上圖分離爲前景與背景圖如下:
- 鼠標焦點放在src目錄上,按下Windows:Ctrl+Shift+A 或者 Mac:command+shft+A 快捷鍵,輸入Image Asset.打開Configure Image Asset窗口,如下:
配置時候,Preview
中有個圓圈表示的是範圍,在這個範圍內展示logo的主要內容,範圍之外的到時候在手機上展示的時候會被自動裁剪掉.Preview
區域的Legacy Icon
圖標表示的是在6.0系統上啓動圖標呈現出來的樣子. - 剩下的就是確認創建啓動圖標,在
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_background
與ic_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
這幾個機型是可以在其他佈局中做到自動適配的.