Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's mipmap-anydpi-v26 in res directory in Android Studio 3.0?

In Android Studio 3.0, once we create a project, a folder named mipmap-anydpi-v26 is automatically created in the res directory. What actually does it do? Why do we need it? How will we utilize it for development purposes?

Also, there are two XML files automatically created in this folder after project setup. Why do these XML files reside in a mipmap folder? I thought we should keep all XML files in a drawable folder instead of mipmap.

like image 294
0xAliHn Avatar asked Jul 13 '17 12:07

0xAliHn


People also ask

What is in mipmap Anydpi v26?

anydpi-v26: This is an additional filter over just anydpi. This says resources will always be picked up from anydpi-v26 regardless of devices density only if SDK/API level is 26 or higher(Oreo). So you can have mipmap-anydpi-v26 or drawable-anydpi-v26. All resource folders will follow above logic.

What is mipmap folder in Android Studio?

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.

How do I install mipmap on Android?

In the Project window, select the Android view. Expand the res/mipmap folder for a launcher icon, or the res/drawable folder for other types of icons. Locate a subfolder that has the name of the icon you want to delete. This folder contains the icon in different densities.


3 Answers

Android Studio 3 creates an adaptive icon for your app which is only available in SDK 26 and up. Launcher icons should be put into the mipmap folders.

If you look at your manifest, you can see that it references ic_launcher

android:icon="@mipmap/ic_launcher"

If you look in your mipmap folder, you see your normal 5 different launcher icons which will be used for anything lower than SDK 26. For SDK 26 and up, it uses the XML files from the anydpi-v26 folder to make use of adaptive icon.

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@drawable/ic_launcher_background"/>
    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
like image 84
tyczj Avatar answered Oct 16 '22 08:10

tyczj


Both answers above give pretty good summary of what mipmap-anydpi-v26 folder does but I feel why part is missing. So heres my 2 cents.

anydpi: These resources take precedence in any dpi. So even if you have mipmap-hdpi or mipmap-mdpi matching with current devices density, resource from mipmap-anydpi will always be picked up.

anydpi-v26: This is an additional filter over just anydpi. This says resources will always be picked up from anydpi-v26 regardless of devices density only if SDK/API level is 26 or higher(Oreo).

So you can have mipmap-anydpi-v26 or drawable-anydpi-v26. All resource folders will follow above logic.

Now that we know the answer of "why mipmap-anydpi-v26"? lets try to understand why "mipmap-anydpi-v26/ic_launcher.xml".

This is because ic_launcher.xml is used to describe adaptive icon for your app which is only available in SDK 26 and up as mentioned by other answers. Hope this helps.

like image 21
Aniket Thakur Avatar answered Oct 16 '22 09:10

Aniket Thakur


I have found an explanation about this, here is some context:

To add an adaptive icon that replaces all PNGs on API 26+ devices, you’ll add a res/mipmap-anydpi-v26/ic_launcher.xml file that looks like this:

<adaptive-icon
    xmlns:android="http://schemas.android.com/apk/res/android">
  <background android:drawable="@drawable/ic_launcher_background"/>
  <foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>

By placing it in the mipmap-anydpi-v26 folder, the resource system will use it in preference over any files in the other dpi folders (exactly what you want, since this file is replacing all of them) and that it should only be used in API 26+ devices.

like image 8
0xAliHn Avatar answered Oct 16 '22 10:10

0xAliHn