I recently installed one more Android SDK to Android Studio, the SDK version 4.4 (API level 19), and after using it with my project, it added a set of mipmap
folders in the project's res
folder (res/mipmap
).
I neither understand why, or how to use them.
I read another question about it here on SO.
The answer to it said that:
The mipmap folders are for placing your app icons 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.
I still don't get the reason to this.
Why cant we just place the app icons in the res/drawable
folders too?
Also, if only the app icon should be placed in the mipmap
folders, how do I create other drawable assets and place them in the drawable
folders with the Android Studio Image Asset wizard? (Accessed by right clicking in the project, selecting New > Image Asset)
Why cant we just place the app icons in the res/drawable folders too?
Oh, you can. Google doesn't recommend it, that's all.
Quoting myself from Version 6.5 of my book:
While drawable resources might be removed when packaging an APK, such as for the Gradle for Android split system for making density-specific editions of an app, mipmap resources are left alone, apparently
This is because launcher icons may be pulled from a higher-density bucket than the regular device density that is used for all other drawables. Putting them in res/mipmap-*/
directories means that we won't inadvertently get rid of them as part of optimizing APK size.
(why they didn't handle this in a better way, I have no idea)
how do I create other drawable assets and place them in the drawable folders with the Android Studio Image Asset wizard? (Accessed by right clicking in the project, selecting New > Image Asset)
The Image Asset wizard only puts launcher icons in res/mipmap-*/
directories. If you choose the other icon types, they will go in res/drawable-*/
. And, of course, the Image Asset wizard itself is optional.
来源:https://stackoverflow.com/questions/28909528/how-should-we-use-the-mipmap-folders-added-with-android-4-4