Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mipmap drawables for icons

Since Android 4.3 (Jelly Bean) we can now make use of the res/mipmap folders to store "mipmap" images.

For example, Chrome for Android stores its icons in these folders instead of the more normal res/drawable folders.

How are these mipmap images different from the other familiar drawable images?

I see that in my manifest, we use the @mipmap/ qualifier, instead of @drawable/, which makes sense given the resource folder name:

<activity     android:name=".MipmapDemp"     android:icon="@mipmap/ic_launcher" /> 

References:

The Android 4.3 APIs document has the following to say:

Using a mipmap as the source for your bitmap or drawable is a simple way to provide a quality image and various image scales, which can be particularly useful if you expect your image to be scaled during an animation.

Android 4.2 (API level 17) added support for mipmaps in the Bitmap class—Android swaps the mip images in your Bitmap when you've supplied a mipmap source and have enabled setHasMipMap(). Now in Android 4.3, you can enable mipmaps for a BitmapDrawable object as well, by providing a mipmap asset and setting the android:mipMap attribute in a bitmap resource file or by calling hasMipMap().

I don't see anything in there that helps me to understand.


XML Bitmap resources have an android:mipMap property:

Boolean. Enables or disables the mipmap hint. See setHasMipMap() for more information. Default value is false.

This does not apply to launcher icons as far as I can see.


The question was raised on Google Groups (The purpose of resource name "mipmap"?!), to which Romain Guy replied:

It's useful to provide an image at a larger resolution that would normally be computed (for instance, on an mdpi device, Launcher might want the larger hdpi icon to display large app shortcuts.)

I feel like this almost makes sense of it, but not quite.

I'm still inclined to go with Randy Sugianto's follow up:

What are the advantages of this? Is there any guide how to use mipmaps, probably for better launcher icons?


Of course, Wikipedia has a page for "Mipmap", which refers to an older technique invented in 1983, that I can't quite relate to the current Android implementation.


Should we be storing all our app icons in res/mipmap folders these days, and what are the guidelines for these mipmap images?


Update #1

Here's a blog post that tries to explain it a bit.

  • Mipmapping for drawables in Android 4.3

But the image used in that blog post shows what looks like one file with many logos in it. This is not what I see in Chrome's mipmap folder.

Chrome's mipmap-hdpi folder contains three images. One is the Chrome logo, on its own.

Chrome mipmap-hdpi icon.png

Strangely, it is 72x72, not 48x48 which I would expect to see.

Perhaps that is all there is to this - we just need to keep bigger icons in the mipmap folders?


Update #2

The Android Developers Blog post of 23/10/2014 again confirms the idea of using the mipmap folders for application icons:

  • Getting Your Apps Ready for Nexus 6 and Nexus 9

When talking about the Nexus 6 screen density, the author writes:

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. For example, an xxxhdpi app icon can be used on the launcher for an xxhdpi device.


Update #3

Note that Android Studio creates the ic_launcher.png icons in the mipmap... folders rather than the drawable... folders that Eclipse used to create them in.


like image 243
Richard Le Mesurier Avatar asked May 29 '14 14:05

Richard Le Mesurier


People also ask

How do I add icons to mipmap android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Further follow the path to reach the desired folder to add icon (app → res → mipmap). Step 3 - Add you app icon. You can just simply copy and paste the image in mipmap folder.

What is difference between drawable and mipmap?

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.

What is mipmap used for?

Android introduced mipmap drawables for providing more flexibility to design the launcher icons. mipmap first introduced in Android Jelly Beans 4.3. If you are building different versions of your app for different densities, you should know about the mipmap resource directory.

How do I add an image to mipmap?

Add images to your Android Project First, download this picture: (Right click and select Save Image As.) Save it to your own computer and remember where you saved it to. All of these folders are from your res directory. (The mipmap ones are used mainly for icons.


2 Answers

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.

like image 122
Kevin TeslaCoil Avatar answered Sep 23 '22 20:09

Kevin TeslaCoil


It seems Google have updated their docs since all these answers, so hopefully this will help someone else in future :) Just came across this question myself, while creating a new (new new) project.

TL;DR: drawables may be stripped out as part of dp-specific resource optimisation. Mipmaps will not be stripped.

Different home screen launcher apps on different devices show app launcher icons at various resolutions. When app resource optimization techniques remove resources for unused screen densities, launcher icons can wind up looking fuzzy because the launcher app has to upscale a lower-resolution icon for display. To avoid these display issues, apps should use the mipmap/ resource folders for launcher icons. The Android system preserves these resources regardless of density stripping, and ensures that launcher apps can pick icons with the best resolution for display.

(from http://developer.android.com/tools/projects/index.html#mipmap)

like image 38
Kazuaki Avatar answered Sep 22 '22 20:09

Kazuaki