Mipmap Drawables for Icons

Mipmaps vs. drawable folders

The mipmap folders are for placing your app/launcher icons (which are shown on the homescreen) in only. Any other drawable assets you use should be placed in the relevant drawable folders as before.

According to this Google blogpost:

It’s best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions different from the device’s current density.

When referencing the mipmap- folders ensure you are using the following reference:

android:icon="@mipmap/ic_launcher"

The reason they use a different density is that some launchers actually display the icons larger than they were intended. Because of this, they use the next size up.

Mipmap drawables for icons

There are two distinct uses of mipmaps:

  1. For launcher icons when building density specific APKs. Some developers build separate APKs for every density, to keep the APK size down. However some launchers (shipped with some devices, or available on the Play Store) use larger icon sizes than the standard 48dp. Launchers use getDrawableForDensity and scale down if needed, rather than up, so the icons are high quality. For example on an hdpi tablet the launcher might load the xhdpi icon. By placing your launcher icon in the mipmap-xhdpi directory, it will not be stripped the way a drawable-xhdpi directory is when building an APK for hdpi devices. If you're building a single APK for all devices, then this doesn't really matter as the launcher can access the drawable resources for the desired density.

  2. The actual mipmap API from 4.3. I haven't used this and am not familiar with it. It's not used by the Android Open Source Project launchers and I'm not aware of any other launcher using.

Android - Storing images in mipmap vs drawable folder

My rule is that if an image will have noticeable changes in quality when they are scaled up or down depending on the android device should be stored in mipmap folders. Examples of such images would be icons, slider bar scrubbers or custom google map markers. Images that don't get affected by changes in scale can be put in the drawable res folder.

What to use mipmap or drawable

Using mipmaps for your launcher icon is described as best practice by the Android team. The advantage you get is that you can keep resources in the mipmap folders for all device densities and then strip out other resources from the drawable folders that are not relevant to the specific users device density.

For example a user has a device that is classified as xxhdpi. The drawable resources in your apk for all other densities, such as xxxhdpi, are not required and can be stripped out.

reference

Does Mipmap scale up or scale down?

I think your confusion about @Kazuaki quote is the now deleted documentation, replaced by: https://developer.android.com/training/multiscreen/screendensities#mipmap

Like all other bitmap assets, you need to provide density-specific versions of you app icon. However, some app launchers display your app icon as much as 25% larger than what's called for by the device's density bucket.

For example, if a device's density bucket is xxhdpi and the largest app icon you provide is in drawable-xxhdpi, the launcher app scales up this icon, and that makes it appear less crisp. So you should provide an even higher density launcher icon in the mipmap-xxxhdpi directory. Now the launcher can use the xxxhdpi asset instead.

The mipmap directories provide that "do not remove when trying to make a smaller APK".

Android mipmap for app icons only

Mipmap is used for app icons and drawables for other assets.

Say you have a device which picks the icon from drawable-xhdpi folder for an asset which is used in the app. Now this same device will pick app launcher icon from mipmap-xxhdpi folder. The reason is that android system wants to display the launcher icons with more crisp and clear view.

Hope my answer is clear.

Alias for mipmap launcher icon

Further attempts show that the code originally posted works fine when compiled onto device, but is just not recognised by Android Studio.

I was hoping to alias the system default launcher icon, and this seems to work:

<resources>
<item name="test_alias" type="mipmap">@android:mipmap/sym_def_app_icon</item>
</resources>

...as do these:

<resources>
<mipmap name="test_alias">@android:mipmap/sym_def_app_icon</mipmap>
<mipmap name="test_alias2">@mipmap/ic_test</mipmap>
</resources>

...where ic_test is a "normal" mipmap in my res/mipmap resources folder.


To explain the use case in my situation, this above code is in a library project. The test_alias mipmap is declared in the library so that I can use it to put up a Notification.

But the intention is that the developer using the library would be able to override this icon with their own launcher, or other icon of their choosing by adding something like this into their own code, overriding the library definition:

<resources>
<mipmap name="test_alias">@mipmap/ic_launcher</mipmap>
</resources>

mipmap/ic_launcher.png still required for SDK =26?


is it enough only to have the adaptive icons present?

Yes.

You must only account for your min SDK version. If your min SDK version is above API 21 you're free to use vector drawables instead of PNG.

Additional sources:

  • https://medium.com/androiddevelopers/implementing-adaptive-icons-1e4d1795470e
  • https://medium.com/androiddevelopers/vectordrawable-adaptive-icons-3fed3d3205b5


Related Topics



Leave a reply



Submit