When I go into the res folder for my project I only see the drawable-hdpi, drawable-ldpi, and drawable-mdpi folders. Every tutorial I've read says put the image in the drawable folder. Am I supposed to have one?
It doesn't get created automatically when you create the project like the others. Just create a folder named drawable in the same location as those other folders. You also do this for anim, animator, values-x, raw, menu, and basically any other specialty resource folder that you may need.
If you have a PNG image file you should place it into drawable-ldpi, drawable-mdpi or drawable-hdpi, depending on its resolutions. Ideally you should provide three versions (or four, with xhdpi) of your bitmap for the different screen pixel densities.
If you have a drawable resource defined in XML that is independent of pixel dentity (e.g. a Shape Drawable) you should place it in drawable.
Select the project tab on the left
Under android Right click on the drawable (under folder "res").
Select Show in explorer or Reveal in finder
You should be able to see the drawable folder
Related
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.
layout show error and images also does not show when i open it in android package:
what is happening I don't know
You have created drawable folder in wrong location you can't create drawable-ldpi or drawable-mdpi etc folders in drawable folder but the they structure like this.
this is how the different drawable folder were created in files system and android studio show this something like this:
to create a drawable in specific folder append with -hdpi, -ldpi, -mdpi, -xhdpi, -xxhdpi, -xxxhdpi same for mipmap and values folders.
hope this will help you.
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.
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..
I have 2 doubts regarding storing the drawables in respective folders ie.. ldpi, mdpi..Which I couldn't find an answer anywhere.
I have folders like this:
Since I have all the possible folder names ie.., ldpi, mdpi, hdpi, xhdpi, xxhdpi should I delete the default drawable folder?
Or Should I move all the files from drawable-mdpi to the default drawable folder and delete the drawable-mdpi folder?
I am using few xml files as drawables, which are selectors, custom backgrounds etc.. Which contain the image references like
<item android:drawable="#drawable/ic_vote_clicked" android:state_pressed="true"/>
<item android:drawable="#drawable/ic_vote_clicked" android:state_focused="true"/>
<item android:drawable="#drawable/ic_vote"/>
Where should I place these xml files? In every folder? Or the default drawable folder?
Anyways the pngs like #drawable/ic_vote are in every folder.
Anything that is not DPI related should go in the drawables folder.
Anything else that is dpi related, should be in the relevant DPI folder.
There is no reason to delete any of the folders.
So your xml files should be in the drawable folder.
Also, it doesnt matter what folder they are in, you still reference them with #drawable/ and it finds the right one.
Android first checks for the resource in the corresponding density specific folder, example: ic_launcher.png for a medium density screen will first be searched in the drawable-mdpi folder. If found, well and good. In case, the image doesn't exist there, android picks from the drawable folder, the default.
hence, to have image resources specific to density, keep them in respective folders and a copy in the drawable folder as well [only for the safe side].
For the xml resources, keep them in the drawable folder only.
Hope that helps.
I created five folders for drawable i.e. ldpi, mdpi, hdpi, xhdpi and xxhdpi. Also for layout i created three folder i.e layout, layout-large and layout-xlarge.
My project requirement was Multiple Device Support. It worked well on all the devices.
Issue was with 10 inch and 7 inch tab. To solve this issue i created layout-large and layout-xlarge folders and place the respective files in respective folders. And now everything is working fine.
So its highly recommended that you create respective folder. Don't move everything to drawable or layout folder.
Put the xml files in default drawable folder. Don't change others.
You shound't delete any of this folders.
Drawable-density folders are using in all element which you want to add i.e. png files. In drawable folder you can add universal graphics, specified i.e. using XML structure (selectors etc.)