I'm trying to import a 600x600 PNG I made into my Android project so that I can use it as a full-sized image in an Activity. Dragging and dropping it onto my /res folder just puts it in that folder, which of course generates an "invalid resource directory name" error.
I can drop it into any of the /res/drawable folders and that works fine, except then it's only in that one folder.
Surely, there's an inbuilt tool which can take my image and scale it appropriately for each /res/drawable folder.
AFAIK there isn't.
What you can do though, is use the drawable-xhdpi folder only. Android will automatically scale down for lower dpi.
The only exception is the launcher icon. You will have to provide all sizes (don't forget xxhdpi for tablets!).
You can find the needed sizes in the Icon Design Guidelines.
It is important to note that the ADT plugin does have tools for generating some icons sets, such as Launcher icons, Actionbar icons and Notification icons.
These tools can be accessed by opening the New wizard (Ctrl + N) and double-clicking Android Icon Set in the Android category.
there's an inbuilt tool which can take my image and scale it appropriately for each /res/drawable folder.
For the scaling part, check out the Icon Generators Tools # Android Asset Studio. There are tools for generating Launcher icons, Tab icons, Action bar icons and (in your case) Generic icons.
Luckily this changed - you are now able to autogenerate different densities - take a look at:
https://code.google.com/p/android-drawable-converter/
If you put your drawable resources in /res/drawable, that resource will be used for all devices.
However, it probably won't do exactly what you want. I would recommend scaling the assets yourself. If that isn't a viable option, then you are stuck with letting Android do the scaling for you.
Related
With older versions of Android Studio, all of the drawable bucket folders were created by default (i.e. drawable-mdpi, drawable-hdpi, etc.). In newer versions of Android Studio, it only provides drawable and drawable-v21. Why is that?
Is there a reason that Android (in its infinite wisdom) no longer gives you the separate bucket folders?
Just to note, I know you can just add them manually, but I want to make sure there isn't some new best practice reason to not use those folders anymore.
Thank you to everyone who tried to help. You helped me reach the final answer, but no one solution was quite right. #user3137702 was probably the closest, as it IS related to the whole move to vectors/SVGs. I couldn't find a definitive answer, like something directly from Google (although I imagine it is out there), but from what I've gathered from a bunch of articles, there is probably a reason they are doing this.
For starters, it looks like this started in Android Studio 1.4. I am in 1.5 right now. It seems that Android is moving in the direction of no longer needing you to create your own density folders (i.e. mdpi, hdpi, etc.) for drawables (mipmaps is different, so please don't confuse that with what I am talking about). As of Android Studio 1.4, it will take the SVGs you put in the regular drawable folder (as in not the v21 folder), convert them to PNGs, and place them in auto-generated density folders for you during the build sequence (so Gradle does this for you, essentially) for all versions older than API 21. For 21 and up, SVG is supported different, which is a whole other topic. But this essentially makes SVG support backwards compatible all the way to API 1!!!
HOWEVER, there is a BIG catch. This SVG conversion is not always as successful as you might hope. It only supports a subset of SVG files, so depending on how you save it (i.e. what settings are applied when saving), it may not render properly. Even commonly used settings, such as gradient and pattern fills, local IRI references, and transformations are NOT supported (yet). If you are working with SVG files that you didn't generate, you will likely have problems importing them. If you or someone you work with directly generates them, you may have to experiment with how you save the files, and you should test builds often on older versions of Android to make sure it turned out as expected.
To import SVGs into Android Studio 1.4+, follow these simple steps:
Right-click on the res/drawable folder
Select "New"
Select "Vector Asset"
At this point, you can select a "Material Icon", which works
really well, and there are a bunch of beautiful "free" icons you can
select from. For indie developers, without icon design support,
this is nice!
OR - you can select "Local SVG File"
Then choose an SVG from either option with the "choose" option. WARNING: This is where it could possibly go wrong, if the SVG you import isn't saved properly.
Hit "Next"
Verify it is saving in the right place, and then Click "Finish"
At this point, it is reference-able with: android:icon="#drawable/ic_imagename" (using your image name instead of ic_imagename, of course)
#CommonsWare's response was very helpful in leading to the right solution, but from what I saw, generating several variations of new projects from different template and version support settings, there wasn't any way to actually have the old density folders get auto-generated. There is definitely more going on here than just a different template-version selection. But as he said, depending on what template/version you select, you may end up with a different set of those two drawable folder types. But specific to my question, Android Studio does seem to be putting an emphasis on this new approach of not creating your own individual drawable density folders at all.
It's pretty cool, imo, but it still needs some work. In practical terms, I will likely still need to add the drawable density folders to support all the images I work with, until this mechanism gets a little more supportive of all types of SVG renderings.
And one more tidbit - Because this is all handled through Gradle (the actual generation of the density folders) you can add build settings through the flavor mechanism to limit which density folders you want to generate. So if, for example, you feel mdpi images have reached the end of their usefulness for your particular user base and would like to leave that size/density out of your app to shave a couple MB off the app size, you can set that in the Gradle build flavor.
I am just getting into an android project that someone else already worked on. I am currently just correcting UI issues and such, and we decided we needed bigger sizes of some graphics that look blurry on tablet size. So we decided to make a few size-dependent folders.
Until now, former guy has placed a lot of graphics into the mipmap folder because it automatically selects images based on density. But now i read that mipmap is only for the launcher icon.
Now my dilemma is whether I should move the graphics or not. It wouldn't be too hard to do, but i tried with a few, and I noticed that when taken out of the mipmap folder, and placed inside the drawables folder, the graphics are suddenly bigger. This means that I either have to resize every single graphic, or replace the file with a smaller version.
I am tempted to leave well enough alone, and not invoke all sorts of re-design processes for the sake of keeping the structure tidy. But on the other hand, it kinda hurts not to.
Does anyone know what I should do, or if mipmap is ok to use for graphics that aren't the launcher icon? And if I am to move it, how do I best tackle all these problems?
Ideally, you would have larger images which are then used accordingly in the relevant drawable folders. Android takes care of resizing these automatically. This is also the reason why the images you have in the minimap folder are being enlarged when exported to the other folders.
If I were you, I would leave the graphic files in the same folder as the previous developer set them. Otherwise you will be getting pixelated images.
The other option would be to use an image-editing software to enlarge the images and copy them to their respective folders.
In the end it is up to you, but if as you are saying, there are many images, I would leave them where they are.
mipmap is ok to use for graphic.in eclipse their are drawables folder to place images but in android studio project mipmap folders are default folder and you can put any type of images it will automatically adjust according to size but put 9paches image in that folder
before when I was creating a new project I was found this folders drawable-hdpi,drawable-mdpi, drawable-xhdpi, and drawable-xxhdpi. but now they are all gone!
is there any explanation of what happens?
and where we should put our images?
This is perhaps because they will add an Gradle plugin that converts SVGs to PNGs during build (as mentioned in this IO talk). The idea is that you will only need to have a single SVG instead of multiple PNGs for various densities (an thus, only one drawable folder). You can still create the folders and use PNGs.
The Gradle plugins for SVG conversion by Google has not been released yet, but you can use Victor or a similar plugin if you already want to use SVGs for your drawables.
You should read Android Blog
you can just create drawable-xhdpi.
I just give answer here
read and if any problem ask.
I wasn't aware that Android Studio ever provided these dpi dependent drawable folders for the built-in default project scaffolding, and indeed, why should they?
Are they supposed to guess that you're going to support each and every one of these resolutions? Perhaps all your graphics will be vector graphics? Perhaps you only target low or high resolutions?
Also, the DPI modifier is only 1 of the possible modifiers you can attach to a resource folder. You can also add locale, screen width / height, mobile country code and many more. Should Android Studio create a folder with each of these options, along with every possible variation? You'd end up with thousands of folders which you'd likely never use.
In addition, creating a folder with no assets inside it is a big problem when you start synchronising your code using Github or something similar, and creating every possible folder with default assets inside seems like a huge waste.
I think the best approach here is to create any resource folder you need when you need it. Google leaves this decision to you.
Also, important: There is no XDPI or XXDPI folder - it's XHDPI, and XXHDPI
Check in your project section, Not in android section, If they gone just simply create them
I recently made an app for android using android studio and set the icon and put it on my phone.
The problem is in the app list the icon appears as the android logos face, but when I manage the app, the icon is correct, and when on my phone I look at the apk its also correct.
Only on the app list is it incorrect.
What I've checked so far is:
Right Click the folder system, New > New > Item asset.
Set this as the application app and the image i want.
Also in the AndroidManifest.xml I've also set the
android:icon="#drawable/ic_launcher"
and on the left, the little image appears.
Any other idea's would be appreciated.
Thanks
If any other info is needed please let me know.
android:icon="#drawable/ic_launcher"
instead of ic_launcher put your drawable name in manifest
Check that you have created app icons for all different DPI's. If you check in your res folder there will be multiple drawable folders, suffixed with the different DPI's such as hdpi, xhdpi etc.
You will have to create versions of your icon for each of the different sizes as the OS will pull the most relevant size for what it needs to display at the time, small ones for the manage app's list, larger ones for your launcher.
There's a handy web tool to do this
http://romannurik.github.io/AndroidAssetStudio/icons-launcher.html
As a side note, the lastest android studio and the above web tool uses a mipmap folder rather than drawable for application icons, you can either just copy the images into their relevant drawable folders or change your manifest to use the #mipmap prefix.
So when I start a small application for Android, (I'm Using Eclipse if that matters) I give my application a name, minimum SDK and such. Then, when it comes down to picking a launcher icon, I created an icon with 1024 x 1024 pixels using Adobe Illustrator (if I'm clearly doing something wrong say so) and export it to .png file.
When I build my android application project, the icon is copied into the different drawable folders (mdp, hdp, xhdp...). So my question is does Eclipse already change the dp of my icon to match the different size screens? And my second question is when I add other icon (not the launcher) do I have to manual change the dp and add it to the corresponding drawable folders.
Sort of. It's not best practice to use the set of icons automatically created by Eclipse, for the very reason you mentioned. Highest quality is always manually creating the images via photoshop/fireworks/your preferred image software following these guidelines:
http://developer.android.com/design/style/iconography.html