layout preview in android studio while working with mipmap - android

I have read this article on mipmap before going through mipmap practically to understand its concept over drawable.
What i've faced is,
While working with mipmap layout-preview is not correct, while using image from mipmap folder.
Is mipmap only for launcher icon ? do i need to manually create all drawable folders(drawable-hdpi, drawable-mdpi etc.) for all other View's (Button, ImageView, etc.) image? If so then why don't android studio is not creating all drawable folder after creating new project?
I've also searched this issue but failed to get any useful or relevant link. I don't know what's wrong with mipmap because it seems fine while run code only layout preview is not correct.
Update :
Currently for workaround i've used mipmap folder only for launcher-icon and for all other Views i've manually created drawable-mdpi, drawable-hdpi etc.
to make layout-preview fine.
Please help!

According to this Google Post
The mipmap folders are only for placing your app icons.
Any other drawable resources(images and drawable .xml) you use should be placed in the relevant drawable folders as before Android 4.3.
This is the 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 referencing the mipmap - folders ensure you are using the
following reference: android:icon="#mipmap/ic_launcher"
You can also check the more about the Mipmap

Yes they are talking about the Launcher icon for the Nexus family. So this would be good practice if you do so. And for other resources you have to keep going in the same way As you always do.

Related

Android Studio: cannot use resource files in drawable foloders

I'm new to Android programming. I was working for UI design stuff using Adobe XD and I exported the stuff I created to Android Studio. I was following this tutorial. And I was trying to use the stuff in drawable folders I created. (like drawable-hdpi) But the stuff that is stored in these folders doesn't show up. Only images that are stored in drawable folder show up. What am I wrong with this?
I mean the files doesn't show up as a suggestion and on this list.
This is the normal behavior.
Folders like drawable-hdpi or drawable-mdpi should contain the same as per name drawables as the drawable folder but with different resolutions.
When you choose a drawable in code or resources you see the drawables contained in drawable folder but at run time depending on the resolution of the emulator/device another drawable with the same name as the original from the other drawable-xxxx folders will be used.
In the dialog in the image you posted if you click on project you may see drawables from the other folders and choose them, but it's always a good practice to use the Drawable folder too.

Android studio does not create drawable folder density wise

I created one project in android studio, android studio didn't create drawable folder density wise as like it used to drawable-hdpi, drawable-mdpi etc. It created mipmap-hdpi, mipmap-mdpi etc.
I read https://stackoverflow.com/a/28065664/2455259 mipmap directory is for launcher icons.
Any other drawable assets you use should be placed in the relevant drawable folders as before.
Then why Android Studio stopped to create drawable folder as like before ? Is it no longer recommended approach to put app resources in drawables ?
It wants you to create them when you need them, you can create one by right clicking on the res folder and then click on add new resource directory, select the drawable as the resource type and then from the list of available qualifiers chose density and then the >> button, then select the density you want.
I think a reason why it was removed is for consistency because density is just one of the many qualifiers you can add to a resource file.
It also makes the folder structure neat, because you might not be using all the drawable folders.
The reason why it created the mipmap-hdpi, mipmap-mdpi folders is because there is already a file in it which is the default launcher icon for a new app, if there was no item in it it would not have created them.
The mipmap folder is used for icons only. The other resources have to be placed in correspond drawables' folders.
It is needed for better icon rendering.

Android Studio - drawable folder missing?

I am using Android Studio version 1.2.2 and this how my res folder looks:
As you can see there are no drawable folders present.
My concern:
Is the drawable has been deprecated and instead of it I have to place all the images used in the app in mipmap folders.
If I need to create the selectors or any shape for a view I need to place it in the "drawable" or the "mipmap".
Does anyone has clue about it?
Is the drawable has been deprecated and instead of it I have to place all the images used in the app in mipmap folders.
mipmap folders are for placing your app icons in only and in case of drawer folder, any other drawable assets you use should be placed in the relevant drawable folders as before.
You should go through Google Blog which says
"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."
If I need to create the selectors or any shape for a view I need to place it in the "drawable" or the "mipmap"
Just create drawer folder if you want to use selectors.
if you are building different versions of your app for different densities, you should know about the "mipmap" resource directory. This is exactly like "drawable" resources, except it does not participate in density stripping when creating the different apk targets.
But if you want to use selectors than you can create a drawable folder..

Theare aren't different drawable folders on Android Studio

I m trying to integrate different image size in my app but the problem is that in Android Studio there are not the drawable-Idpi,mdpi,hdpi,xhdpi folders.
I ve checked already other threads and the answers were that I just need to skip into the Project view instead of the Android one. But the results are the same. There is just one generale folder called drawable
And if I try to add another resource folders the drawable is missing.
Just create a new folder:
Right click 'res' folder --> New --> Android Resource Directory.
In the wizard, select drawable as 'Resource Type'. And then 'Density' from the resource qualifiers.
With regard to the 'mipmaps' folders, Android now prefers app icons in these folders because it can use an icon in a different density to the screen density.
More about mipmaps here: http://android-developers.blogspot.de/2014/10/getting-your-apps-ready-for-nexus-6-and.html
I had the same problem before.
I fixed it by downloading an icon that i wanted from http://www.icons4android.com/
now this site provides all the drawable-Idpi,mdpi,hdpi,xhdpi folders for download for each icon they have, I just highlighted all the drawable-Idpi,mdpi,hdpi,xhdpi folders, copied them, and then pasted them to android studio res folder.
(I did this in android view)
I hope this helps
You can create folder same as drawable, drawable-hdpi, mdpi, xxhdpi ... etc
Its look like
But when you see source code using
Add images in draweble its ask you in which folder you want to add(copy n past images in studio)
You can directly creat folder in res its also work...

confusion about drawable-hdpi,drawable-mdpi,drawable-ldpi and drawable

I am on one really big project that was started sins the time of android 1.5.
This project evolved as android was evolving and at this point supports 2.3 and above.
Now I got this problem I have a lot of drawables in drawable-hdpi,drawable-mdpi,drawable-ldpi but also in drawable folder.
Generally the concept of this 3 folders(drawable-hdpi,drawable-mdpi,drawable-ldpi) it is clear to me but my confusion comes with the images in drawable folder.
for example I have an image named myimage.png and this image is present in drawable-hdpi,drawable-mdpi,drawable-ldpi folders with resolution 72x72,48x48,36x36 respectively but this image is also present in drawable folder.
My question is why ? when does the image from drawable folder is used ? is this image forgotten to be removed ? of it is used in some cases ? I have tried to remove this image and the application works just fine. I also have put just a green color with resolution 72x72 and this image is never drawn
so can someone clarify me the existence of the drawable folder ?
I know that if I do not have the dhpi,mdpi and ldpi folders then I need to put the images in drawable but what is the point of images in drawable when this 3 folders are present ?
Thanks
EDIT
one more question, what if I have image in drawable-hdpi but not in ldpi and not i mdpi. Let say we have phone with mdpi resolution density... What will happen ?
drawable folder is used for default images if the images are not found in the respective folders then it will look into the drawable folder.
I found this phrase in the doc:
For example, imagine you have an application icon, icon.png, and need unique version of it for different locales. However, two locales,
English-Canadian and French-Canadian, need to use the same version.
You might assume that you need to copy the same image into the
resource directory for both English-Canadian and French-Canadian, but
it's not true. Instead, you can save the image that's used for both as
icon_ca.png (any name other than icon.png) and put it in the default
res/drawable/ directory. Then create an icon.xml file in
res/drawable-en-rCA/ and res/drawable-fr-rCA/ that refers to the
icon_ca.png resource using the element. This allows you to
store just one version of the PNG file and two small XML files that
point to it. (An example XML file is shown below.)
Please refer this link for more clearity.
AFAIK you don't need drawable folder if you have all three types of folder (drawable-hdpi,drawable-mdpi,drawable-ldpi )with different resolution images.
As per I faced when you run the app on Android 1.5 and 2.0 if the images which is used in any layout is not available in folder 'drawable' then the project gives error "Resource not found" even if the image is present in other hdpi,mdpi or ldpi folder.
This is not about the densities there are other qualifiers as well, though in most of the cases we don't use them much. For list of qualifiers check here and here. You can use -finger -language ... etc qualifiers. In case you want to provide qualifier default resources[in this case drawable] you can opt for default drawable folder. Or many default folders without qualifiers added behind them
I think this page should help you understand better. Thank you for the question. I, myself, didn't know the answer. Basically you have 4 different versions and if no exactly matching version exists, the default one (without qualifier) is used.

Categories

Resources