There is a problem in the project. The icon of the APP on Android 8.0 is the default icon of the robot. What is the problem? Originally, Android 8.0 (API level 26) introduced the adaptive launcher icon, which can display various shapes in different device models. Check out the official cool GIF below:
Figure 1. Adaptive ICONS support different masks between devices.
You can define two layers to control the appearance of the adaptive launcher icon, including background and foreground. You must provide an icon layer as draftable, without masks or background shadows around the icon outline.
Figure 2. Adaptive ICONS are defined with 2 layers and 1 mask.
In Android 7.1 (API level 25) and earlier, the launcher icon size is 48 x 48 dp. The following rules must be used to resize the icon layer:
- Dimensions of two layers must be 108 x 108 DP.
- The icon’s inner 72 x 72 DP appears inside the mask viewport.
- The system leaves 18 dp on each side to produce interesting visual effects such as parallax or pulses.
I’ve verified that it’s okay not to be in these sizes, but let’s stick to these guidelines.
Figure 3. Adaptive ICONS support a variety of visual effects.
Note: If you do not update the launcher icon with the necessary layers, it will look inconsistent with other ICONS displayed in the system UI and will not support visual effects.
Create adaptive ICONS with XML
Let’s first create a Sample project, as shown below:
One more res/mipmap-anydpi-v26 file than before, open, with background and foreground.
ic_launcher_background.xml
<?xml version="1.0" encoding="utf-8"? >
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillColor="#26A69A"
android:pathData="M0, 0 h108v108h - 108 z" />
<path
android:fillColor="# 00000000"
android:pathData="M9, 0 l9, 108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<! -- Omit some code -->
</vector>
Copy the code
ic_launcher_foreground.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillType="evenOdd"
android:pathData="M32, 64 c32, 64, 38.39, 52.99, 44.13, 50.95 C51.37, 48.37, 70.14, 49.57, 70.14, 49.57 L108.26, L108 87.69, 109.01 L75.97, 107.97 L32, flashes 64 z"
android:strokeColor="# 00000000"
android:strokeWidth="1">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="# 44000000"
android:offset="0.0" />
<item
android:color="# 00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<! -- Omit some code -->
</vector>
Copy the code
and
support Android :drawable, PNG and ic_launcher_foreground. PNG,
and
also support @color/ resource name.
<?xml version="1.0" encoding="utf-8"? >
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<! --<background android:drawable="@color/colorAccent" />-->
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
Copy the code
The listing then uses the Android: Icon property to specify drawable resources, and you can also use the Android :roundIcon property to define icon drawable resources.
<application
…
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"... >
</application>
Copy the code
If you want to apply the same mask and visual effects of the general adaptive launcher icon to the shortcut, use the following:
- Use this for static shortcuts
<adaptive-icon>
Elements. - For dynamic shortcuts, see
createWithAdaptiveBitmap()
This method is called when the method is created.
There you have it. Android 8.0 is adaptive. Here are the default ICONS.
Note: Compilers below Android Studio 3.0 cannot find the adaptive icon tag, this is not verified.
The source code
AdaptiveIconsSample, obtain the complete Sample code.
The public,
My official account: Wu Xiaolong, welcome to exchange ~