Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusion about drawable and mipmap in Android Studio from older example in book

[Disclaimer: First of all I know there are many posts about the drawable and the mipmap folder, I read a descent bunch of them]

From the book Android Programming - The Big Nerd Ranch Guide there is an example in which I have to insert an icon next to some text on a Button. For higher resolution screens it would make sense to include multiple sizes of the icon. In their solution they have all their images in many different Drawable folders with different resolution sizes of the image.

I got it working by just putting the icons in the drawable folder after a lot of trial and error to get it working in the mipmap folder:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/next_button"
    android:text="@string/next_button"
    android:drawableRight="@drawable/arrow_right/"/>

However, I got some confusion about how it works:

  1. People often say that only the app icon should be placed in the mipmap folders, is that true? What is the app icon? Others say that only the launcher icons should be placed there while still others say that only icons should be placed there. Which one is it, they are mutually exclusive options!
  2. I can't auto-complete into the mipmap folder within Android Studio which makes me think that I have to put everything into my drawable folder since there Android Studio does auto-completion for me. But, by default the drawable folder has no sub-folders. This leaves me to believe that the drawable folder should no longer be used for images of different resolutions, since why else would the default be no folders, so everyone can make spelling mistakes..
  3. When would it not make sense to have icons available in different resolutions? I can't imagine someone not wanting the highest possible resolution..

From here I got some of my confusion:

The mipmap folders are for placing your app icons in only.

What does that mean? From google translate I get:

icon: a symbol or graphic representation on a screen of a program, option, or window, especially one of several for selection.

like image 751
Joop Avatar asked Apr 23 '15 12:04

Joop


People also ask

What is the difference between drawable and mipmap in Android?

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 drawable in Android Studio?

A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.

Which of the following Android studio folders includes drawable files for different?

In Android Studio inside the res folder, one can find the drawable folder, layout folder, mipmap folder, values folder, etc. Among them, the drawable folder contains the different types of images used for the development of the application.


1 Answers

Different uses of mipmap and drawable folder

I finally understood the difference uses between mipmap and the drawable folder by looking at the official google documentations of the resource folder (res/).

They say when to use mipmap:

Drawable files for different launcher icon densities. For more information on managing launcher icons with mipmap/ folders, see Managing Projects Overview.

And when to put something in your drawable folder:

Bitmap files (.png, .9.png, .jpg, .gif) or XML files that are compiled into the following drawable resource subtypes:

Bitmap files

  • List item
  • Nine-Patches (re-sizable bitmaps)
  • State lists Shapes Animation
  • drawables
  • Other drawables
  • See Drawable Resources

Qualifiers appended to folder-names have special meaning in android

Also noticeable is there is for the launcher icon by default multiple folders with different resolutions but for the drawable folder there is not. Android OS looks for these folder with special names, called qualifiers. For instance for the drawable folders there are these qualifiers and more:

  • ldpi
  • hdpi
  • xdpi

These qualifiers are appended to these resource folder names like drawable-ldpi, drawable-hdpi and drawable-xdpi so the android operating system will look into these folders to find the best resolution of the files in the folders.


To answer the questions from above:

  1. People make the mistake of using the term icon when they actually mean launcher icon. The launcher icon should be placed in the mipmap and is there by default.
  2. Nothing besides the launcher icon should be placed in the mipmap
  3. Android provides configuration qualifiers to make it easier to change the app based on specific device settings like screen resolution and screen orientation. It makes a lot of sense to include different size versions since downscaling and upscaling can then be done much more accurate to fit all kind of screen sizes.

Hope this helps anyone. I found this hard to find.

like image 68
Joop Avatar answered Sep 23 '22 03:09

Joop