I was trying to add some images to my project in Android Studio however I noticed that I only had the drawable folder, neither of other (drawable-hdpi etc.) folders were there.
So I decided to put them by hand, just created the folders with appropriate names and placed the images:
However It still kept giving this error which I couldn't handle. Why this error occurs and how to solve it?
Thank you.
drawable-* folders should be under res and not under res/drawable.
Different home screen launcher apps on different devices show app launcher icons at various resolutions. When app resource optimization techniques remove resources for unused screen densities, launcher icons can wind up looking fuzzy because the launcher app has to upscale a lower-resolution icon for display. To avoid these display issues, apps should use the mipmap/ resource folders for launcher icons. The Android system preserves these resources regardless of density stripping, and ensures that launcher apps can pick icons with the best resolution for display.
Make sure launcher apps show a high-resolution icon for your app by moving all densities of your launcher icons to density-specific res/mipmap/ folders (for example res/mipmap-mdpi/ and res/mipmap-xxxhdpi/). The mipmap/ folders replace the drawable/ folders for launcher icons. For xxhpdi launcher icons, be sure to add the higher resolution xxxhdpi versions of the icons to enhance the visual experience of the icons on higher resolution devices.
Note: Even if you build a single APK for all devices, it is still best practice to move your launcher icons to the mipmap/ folders.
check here
and here too.
Related
I have a bit of a weird bug/issue with one of the apps I'm working on. On some devices running Android 6, the app icon is smaller in comparison to the rest of the icons from other apps.(See attachment) Any idea why?
I've checked and the ic_launcher have the right resolution - according to this: Android - Launcher Icon Size
Probably also worth mentioning that the icons were generated using the icon generator within Android Studio.
Thanks!
Drawables and mipmaps are nearly identical even mipmaps are mostly used for launcher icons and drawables for other things. The suffixes (e.g., -mdpi, -hdpi) are filters,
indicating under what circumstances the images stored in those directories should
be used. Specifically, -ldpi indicates images that should be used on devices with
low-density screens (around 120 dots-per-inch, or “dpi”). The -mdpi suffix indicates resources for medium-density screens (around 160dpi), -hdpi indicates resources for high-density screens (around 240dpi) and so on.
Android Studio offers an Image Asset Wizard. This wizard is designed to take a
starter image and give you icons, in a variety of densities.Android will calculate density of the screen on which app is installed and by that it will take the correct icon. If there is non than Android will take the nearest one. You can find more about mipmaps and drawables on official developer site or any relevant book about android programming like The Busy Coder's Guide to Android Development.
There is Android Asset Studio which you can use in Chrome browser to generate your icons: https://romannurik.github.io/AndroidAssetStudio/
it seems that the problem was the selected shape when generating the icon with the Images Asset tool in Android Studio. Square is selected by default. Selecting none fixed the issue.
While working on an app, I noticed that there are different files such as drawable and drawable-hdpi. So I found out that these folders are for different icons and images size. My problem is that these two are two separate folders and I was wondering if I have to direct the android to the icons in the separate folder?
By that I mean do I have to first figure out what kind of dpi the device is and set the appropriate icons or can I just declare one drawable resource and android will figure it out for me?
If I can just set an icon name and the drawable file and the android system will know what to use for the different screen, then can you explain to me how this is done? I mean it is two separate files drawable and drawable-hdpi. So how can just set an icon image in the drawable folder and android knows what to access for the drawable-hdpi for the different device?
There are several questions bundled in one, but I will explain all of them in detail.
As you know, there are a variety of Android devices with different screen sizes. That is why, they are separated into a few categories based on their density. Must read this, if you haven't already.
This is the full classification,
So the idea is to have all these directories separately and not just a single "drawable" folder. Whenever you want to put any image or icon in your app, you need to put different sizes of them in their respective directories correctly.
two separate folders and I was wondering if I have to direct the
android to the icons in the separate folder?
You do not have to direct Android to do anything. Android will automatically pick the right image size from the "drawable-**dpi" intelligently.
By that I mean do I have to first figure out what kind of dpi the
device is and set the appropriate icons or can I just declare one
drawable resource and android will figure it out for me?
You can't figure out dpi of all devices, as your app will run on several devices having different densities. You just need to put different sizes of your icons in their respective drawable directory.
You should never put a single image or icon in the "drawable" directory as it can drastically slow down your app as Android need to dynamically resize your images at runtime.
If I can just set an icon name and the drawable file and the android
system will know what to use for the different screen, then can you
explain to me how this is done?
Just refer to the previous question, its already answered.
So how can just set an icon image in the drawable folder and android
knows what to access for the drawable-hdpi for the different device?
As explained earlier, Android obviously knows which device the app is currently running and thereby knows its screen density. Now it is very easy for Android just pick the right image based on the current screen density if you have put them properly in their respective drawable folders.
UPDATE
Just to answer your new question.
You start out with one "drawable" folder. But you need to create the other directories yourself and they need to have the proper name like drawable-mdpi, drawable-hdpi, drawable-xhdpi, etc.
You cannot have any other name like drawable-K or drawable-l, or not even a spelling mistake in the names. Android just scans to see if the folders with these names exists in your app, if so, then it will pick right one.
Suppose you are using a Nexus 5 which is an xxhdpi device,
i) Now Android will look for the drawable-xhdpi directory in your app for a particular image.
ii) If it exists, then it will just pick it up. If it doesn't then it will look for the nearest ones like drawable-xxhdpi or drawable-hdpi and resize the image slightly to fit.
iii) If nothing exists, then it will pick the image from the raw "drawable" folder.
Hope it clears all your doubts.
When you include icons for multiple screen sizes in your Android application are the icons that don't apply to that screen size purged when the application is installed on a device? For example, if I have a tablet that has an xlarge screen that has a xhdpi density are the icons in the drawable-ldpi, drawable-mdpi and drawable-xhdpi folders purged when the application is installed (assuming drawable-xhdpi has all the necessary icons)?
Yes. All resources in will be included in the apk. The apk is the installed application; there's no point at which the resources are copied elsewhere before running it. You can confirm this by installing your app on a Nexus 10, then using adb to make it emulate other dpi targets. Even though you've installed the apk when the device was at a xxhdpi, relaunching it at mdpi doesn't kick off another install, the mdpi resources are already there.
A solid strategy for reducing the size is to simply not use large images when they're not necessary. I use conservative 9-patches and substitute xml drawables for shapes when appropriate. If you've done everything you can and you're still concerned with the apk size, you can create multiple apks that target different dpi points.
It has to have one of each of those icons in the apk. So it will increase the size.
Yes it will but you can use programs like OptiPng to compress your PNG Images so the size of the application wouldn't be affected much.
For some reason, the drawables in my app are blurry. This is especially apparent in menus when I put built-in system icons side-by-side with icons from my project's res folder.
Here's an example. The left envelope icon is in my app's drawable-hdpi folder. It is scaled down, for some reason. The right one is using the built-in Android resources. As far as I can tell, they are the same 72x72px file--I copied the png straight from the drawable-hdpi folder in SDK to my project's drawable-hdpi folder.
Is there some special setting for drawables in my app that I'm missing?
Try adding the appropriate supports-screens element to your Android manifest, and make sure you have a min-sdk of at least 4. Also make sure your uses-sdk element is nested under the manifest and not under the application (if it's in the wrong place or missing, your app will still work but can cause issues with compatibility-related code like resource scaling, and will prevent uploading to the market with an obscure error... it can be a tough one to track down).
Are you using an mdpi screen? If so then your device is having to take the drawables from drawables-hdpi and scale them down, which would likely cause them to blur.
You might try also copying the -mdpi resources to your drawable-mdpi folder, which would allow the framework use your drawables without adjusting for screen density.
Edit - now that I think about it, I'm not sure why your image would appear smaller unless your screen had a greater dpi than hdpi.
On the topic of included standard icons the Android documentation mentions that:
Shown below are standard menu icons
that are used in the Android system.
Because these resources can change
between platform versions, you should
not reference the system's copy of the
resources. If you want use any icons
or other internal drawable resources,
you should store a local copy of those
icons or drawables in your application
resources, then reference the local
copy from your application code. In
that way, you can maintain control
over the appearance of your icons,
even if the system's copy changes.
Note that the list below is not
intended to be complete.
In my application I'm using such standard icons such as "ic_menu_sort_alphabetically" and thus I've tried to find these icons, so that I can include them in my application.
However, in "android-sdk/platforms/android-8/android.jar" I only find the icons in drawable-mdpi and in drawable-hdpi - there is neither a default drawable folder with icons, nor a drawable-ldpi folder with low-resolution versions of these icons. However, such a low-resolution version would be required to provide native versions on ldpi devices such as the HTC Wildfire.
Are there any "official" versions of the Android icons scaled at ldpi? While it's likely that the ldpi versions are stored somewhere on my HTC Wildfire device, I assume that they are copyrighted by HTC and not under the same open-source license as the icons in the Android distribution.
If you can't find the pre-scaled images, you can just open the mdpi in Photoshop or GIMP and resize them by 75% to make the ldpi icons. To make hdpi resize the mdpi image by 150%.