banner
jzman

jzman

Coding、思考、自觉。
github

Adaptive icons in Android 8.0

Android 8.0 introduced adaptive app launcher icons, which can display different icons on different devices. For example, an adaptive icon can appear as a circle on one device and as a square on another device. Each OEM manufacturer provides a mask, and the system automatically renders the adaptive icon into the same shape. Adaptive icons can also be used in settings, sharing, and other areas where a consistent icon style is desired.

  • The mask supported by adaptive icons varies depending on the device.

The appearance of adaptive icons can be controlled by defining two layers: the background and the foreground. An image without a background or shadow must be provided as the shape of the icon.

  • The foreground, background, and mask of adaptive icons.

Before Android 7.1 (API level 25), launcher icons had a size of 48 * 48 dp on standard screen density. Now, adaptive icons must follow the following standards:

  1. The size of the foreground and background layers must be 108 * 108 dp.
  2. The size of the visible area of the mask is 72 * 72 dp.
  3. The system reserves 18 dp outside the icon to create interesting visual effects, which may vary depending on the launcher of different devices.

Note: The minimum radius of the mask specified by OEM manufacturers is 33 dp.

  • Creating adaptive icons

The Image Asset Studio tool provided by Android Studio can be used to create adaptive icons. This tool can generate a set of icons with corresponding resolutions for each universal screen density. Additionally, Image Asset Studio can generate a series of other icons that need to be adapted. The following is the interface of Image Asset Studio:

image

After selecting the foreground and background, Image Asset Studio will automatically generate icon files with corresponding resolutions, as shown below:

image

In the above directory, the mipmap-anydpi-v26 directory is for launcher icons created for Android 8.0 and above. When the Target SDK Version is above API 26, the system will automatically select the icon files in this directory as the application icon files. The content of the icon file is as follows:

<!--ic_launchr.xml-->
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/ic_launcher_background"/>
    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

In the above file, a color is chosen for the background and an image is chosen for the foreground. The final result of the generated adaptive icon file is compared as follows:

BackgroundForegroundOverlay Effect
#4E4C9Eimageimage

Of course, for versions before Android 8.0, the corresponding icon files with the appropriate resolutions will be used, making it convenient to adapt the icon files.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.