65

At some point in an Android project you will need to import some drawables - be it toolbar icons, images, UI features - in res/drawable directory. Most of the times you have images scaled for the most common qualifiers (drawable-hdpi, drawable-mdpi, drawable-xdpi, drawable-xxdpi, ...).

So we need to do three, four, even five file copy/pastes for each drawable:

external_dir/drawable-mdpi/file.png   ->  my_package/drawable-mdpi/file.png
external_dir/drawable-hdpi/file.png   ->  my_package/drawable-hdpi/file.png
external_dir/drawable-xdpi/file.png   ->  my_package/drawable-xdpi/file.png
external_dir/drawable-xxdpi/file.png  ->  my_package/drawable-xxdpi/file.png

That is annoying if you have to import multiple pics. Is there an easy, quick way to transfer these four instances of file.png right in the corresponding package folder? Some function implemented in the IDE? Some easy workaround?

My workflow until now has been:

  • copy/paste from OS file manager, from the external directory to the package, and then refresh the resource files in Android Studio. That implies opening each one of the qualified subdirectories, so four moves;
  • from the OS file manager, move to external_dir, search for file.png, get the four instances in a single list, drag&drop into Android Studio, then for each pic right click on the nav bar, Copy, and Paste in the corresponding package directory. Not really better!

Any advice?

Edit - I'm not really asking for "advices" of course - I want to know if there's a way to drop the number of moves to one (or such).

natario
  • 24,954
  • 17
  • 88
  • 158
  • 3
    In Windows Explorer, I just select and copy the four drawable directories, and paste them in the res directory. So I "overwrite the drawable directories". Works perfectly. – Rob Meeuwisse Mar 05 '15 at 17:53
  • Watch link [http://stackoverflow.com/questions/28700593/how-to-import-set-of-icons-into-android-studio-project][1] [1]: http://stackoverflow.com/questions/28700593/how-to-import-set-of-icons-into-android-studio-project – Shinichi-kudo May 16 '15 at 08:11
  • One of the things I miss about Eclipse. I used one of the asset creators which delivers your new assets as a zip file with a root directory of "res". In eclipse I used to just drag this root and drop it on the application node in the project explorer and it would copy the new content without deleting the old. Gave me an "oh s**t!!!" moment the first time as it does warn you that it will replace the entire directory... – William T. Mallard Feb 20 '17 at 21:58

14 Answers14

63

Check android-drawable-importer-intellij-plugin

TooCool
  • 10,598
  • 15
  • 60
  • 85
  • 4
    Thank you. I accepted this answer because it, well, answers, plus points to a tool that will be useful also in different situations. – natario Feb 13 '15 at 22:05
  • Why does using this make my app laggy.I have one image and i convert it using this software.But it makes my app very laggy – Arjun Anil Nov 18 '17 at 19:59
  • @DragonFire, Yes I face same issue. – Ali A. Jalil Mar 07 '20 at 11:17
  • i am also facing same issue in 3.6.1 – MaKi Mar 17 '20 at 06:31
  • This plugin is not working for android studio 3.6 and so on but, I found this answer that worked for me: [StackOverFlow answer](https://stackoverflow.com/a/60795443/9069090). [Download drawable importer from here](https://gpskaihu.nz/ADI-hack/ADI-hack-plugin-AS36.zip) – Luis Aguilar May 07 '20 at 16:03
  • I'm also facing problems in Android Studio 4.0.1 – Mohamed Salah Aug 30 '20 at 06:15
37

This became a lot easier since Android Studio 3.4. Simply go to the Resource Manager-tab and click the little add-button add resources to the module. [add button within resource manager[1]

Then select the drawables you would like to import. If you placed the drawables in folders with the same name like the qualifiers (drawable-mdpi, drawable-hdpi. drawable-xhdpi and so on), the tool will automatically know were to add them. drawables import dialog

The only thing still missing in my opinion is adding the drawables to a certain flavorDimension.

Wirling
  • 4,810
  • 3
  • 48
  • 78
18

My Answer on Jan 16, 2017.

Two years later, Android Studio has a way to import Image Assets. But I wanted to add a new comment. Android now supports Vectors, so we don't have to worry about different resolutions. I suggest to use Vector and VectorDrawable.

Just right click your app name in the Project -> New -> Vector Asset.

Just follow the wizard.

Best regards, Pedro.

My Answer on Feb 18, 2015.

If I don't misunderstood, this is what I do in my Android Studio (AS) projects.

I found out that we only need to import the highest resolution resource; AS will scale them for you. I ask my designers to only generate xxhdpi files and then.

You go to your /res folder in the Project navigator, right click and select New -> Image Asset

Asset Studio will pop up

In there you can,

  • Select your asset type

[ Launcher Icon, Action bar icons, Notification icons ]

  • Browse you original file
  • Name your resource

After you have completed all the information. Your resource will be imported in AS.

As a general note. For inner icons other than the launcher icons, I selected as type "launch icon", and they work perfectly.

Hope this help.

Best, Pedro.

aleksandrbel
  • 1,422
  • 3
  • 20
  • 38
Pedro Varela
  • 2,296
  • 1
  • 26
  • 32
  • Couldn't believe there was not a built-in tool. Thank you. – natario Feb 13 '15 at 22:04
  • I would not recommend this, those icon types have set sizes (in dp), and if your custom asset is not one of those specific sizes, Android studio will scale your icon to meet whichever icon type size that you pick, making your icon either larger or smaller than you intended... – Steven Byle Feb 19 '15 at 23:37
  • @Steven sorry, I didn't get it. You mean it's risky because you have to use an icon of the exact right size, otherwise it would be scaled wrong? – natario Feb 20 '15 at 10:21
  • 1
    @miav Sort of, I mean Android forces the icon it generates to be the proper size of that icon type (launcher = 48dp, action bar = 32dp, notification = 24dp). If you have a custom icon that is 36dp x 36dp (108x108px @ xxhdpi), and you choose launcher, the icon it generates will be 48x48dp (144x144px @ xxhdpi), which is not the size you intended to import. I made the same mistake when first trying to import with AS, and realized afterwards the icons AS was putting in was not the size in dp that I started with. – Steven Byle Feb 20 '15 at 13:42
  • 1
    @Steven got it, nice to know. If one could set desired size in dps this would be a pretty complete tool. – natario Feb 20 '15 at 13:51
  • @StevenByle yeap, you are right, I haven't realized about that, as my apps seems to look well I posted this a possible solution. So, do you know what is correct way to import assets in AS? – Pedro Varela Feb 20 '15 at 19:58
  • @StevenByle yeap, you are right, I had not realize it, as my apps seems to look well I posted it a possible solution. So, do you know what is correct way to import assets in AS – Pedro Varela Feb 20 '15 at 20:01
  • 1
    @PedroVarela I unfortunately do not have an answer (that's how I ended up on this question). I tried the plugin referenced in the accepted answer, but it looks like it has a bug with AS 1.0.2 and does not show up, which was logged against it in GitHub. – Steven Byle Feb 21 '15 at 17:21
  • Why doesn't this method work for me? There is no new directory created when I import a png file. – the_prole Aug 28 '15 at 22:32
  • Hello everyone, After a while the designer of the company I worked, told me about and script that helped them export from illustrator to different resolutions, he send me the script, I don't know who is the author, so I read it, improved it and tested it, and it does exactly what we wanted, custom assets with different resolutions. Heres the link {https://dl.dropboxusercontent.com/u/592105/SaveAndroid.jsx} It takes the illustrator artboard and export it to png. Hope it helps you. – Pedro Varela Apr 26 '16 at 17:14
  • Now there's only one thing missing to make your answer perfect. There should be an easy way of importing several SVGs into an Android project with Android Studio. I'm still looking for it. Sometimes it can be a bit tiring to manually import, for example, 10-20 SVGs. – xarlymg89 Aug 14 '18 at 10:14
  • When I tired importing an image with 'Adaptive and Legacy' option instead of 'Legacy' only, the image was being rendered in a circle on the app. The preview would show it as a square (desired view) but in the app it was rendered in a circle within the square layout. Can anyone explain this behaviour ? When I imported the image using only 'Legacy' option it rendered correctly as a square – sushrut619 Feb 27 '19 at 17:03
  • @PedroVarela you asked to use vector asset. How could I use coloured image as a vector asset? Whenever I am converting the coloured png image to svg, it becomes a monochrome image and the fill colour of every path of the vector asset becomes #000000. How to deal with this (I am using online png to svg converter)? – LSG Jun 23 '20 at 16:24
  • 1
    @LSG converting PNG to SVG it is not what you have to do. You want your SVG files created from an editor software like Adobe Illustration, Affinity Designer, etc. You have to create a vectorized version of your asset. If you don't have those skills there are a lot of options out there to find SVG assets, Google for instances has some predefine vectors that you can use in your projects https://material.io/resources/icons/?style=baseline. Please also read this guide. https://developer.android.com/studio/write/vector-asset-studio – Pedro Varela Jul 14 '20 at 17:40
  • @PedroVarela I got one svg created by Adobe illustrator, but it does not work for android. It shows some error that the file is not allowed in android. Probably it goes under the limitation section. Ath this case, what should I do? – LSG Jul 14 '20 at 19:19
  • 1
    @LSG that might be too many things. i am not a graphic designer nor i know the tools well. your SVG on android can't exceed 200 x 200 dp, so design for that size. I don't know what is your error so it is hard to know what is going on. you have to import your SVG into android studio, read the guides. you cannot user your raw SVG in your project. good luck. – Pedro Varela Jul 15 '20 at 18:58
12

As Rob Meeuwisse mentioned in a comment above, you can do it in one copy and paste action. Rather than copy and paste each of the files one by one, you can instead select all four drawable-XXXX folders (not the images themselves!) in your OS file manager at the same time (by Ctrl-clicking in Windows/Linux or Command-clicking in OS X), copy all these folders and then paste them into the res folder in Android Studio.

The images will automatically be pasted into the appropriate drawable folder in res. This works because if Android Studio notices that you're copying and pasting a folder that already exists in the project, it will simply use the existing folder and paste in what's missing rather than replace/discard the files that are already there.

mannykary
  • 812
  • 2
  • 10
  • 18
  • Yep - but not useful if your `drawable-XXXX` folders have hundreds of files, only one of which needs to be imported (this is the most common case for me, as I tend to import icons from material sets) – natario Mar 22 '15 at 18:19
2

I usually do it in a very simple way: I use this tool to generate my images directly in the right folders names: you just have to open the tool and drag on it the bigger image (EG: the one you want to use for xhdpi folder or xxhdpi folder): the tool will create in the original image's folder all the other folders (mdpi,ldpi,hdpi etc) containing the image properly scaled. Once you have this folders you just have to paste them in res folder, DONE!

Apperside
  • 3,542
  • 2
  • 38
  • 65
2

With Mac OS X Finder you can simply copy/paste the folders drawable-mdpi, drawable-hdpi, drawable-xdpi, drawable-xxdpi in a single move to my_package/ and then select the option Merge in the appearing Finder dialog. This will add the new files to the corresponding folders in my_package/.

However, note that this is only possible if the source and target folders do not contain any identically named files.

weibeld
  • 13,643
  • 2
  • 36
  • 50
2
  1. Select the "res" directory
  2. Right click and select "Compare with"
  3. Find the directory where your drawables are coming from
  4. Hide outgoing changes
  5. Select all the incoming changes and click the arrow to synchronize.
Cal
  • 359
  • 3
  • 5
0

It seem the way to do it is drag and dropping the resources to AS. For instance. We have a bunch of images, we grab all the xxhdpi images drop them in AS and then it will ask you which resolution are those images, so we choose from the pouup xxhdpi.. then, all the images in xhdpi drop again choose xhdpi from pop up, and that's the way to import assets to A.S. and so on with each resolution.

Community
  • 1
  • 1
Pedro Varela
  • 2,296
  • 1
  • 26
  • 32
0

In your Android Studio, Right click drawable -> New -> Image Asset -> Asset Type: Action Bar and Tab Icons. Image file: image_path, Resource Name: image name -> Next -> Finish

Done

This will add 4 different sizes of your image so that it will fit depending the device size

Vishal Kumar
  • 4,419
  • 1
  • 25
  • 31
0

If you download your icons from https://material.io/icons/, you can use the following Bash function to import a bunch of icons in one go:

import_icons() {
  project_dir=${1%/}
  shift 1

  for zip in "$@"; do
    unzipped_dir=${zip%.*}
    echo $(basename "$unzipped_dir")
    unzip "$zip" -d $(dirname "$zip") >/dev/null
    cp -R "$unzipped_dir"/android/* "$project_dir/app/src/main/res"
  done
}

Usage example:

$ import_icons ~/Projects/MyProject ic_1.zip ic_2.zip ic_3.zip

cp -R copies the various source mdpi, hdpi, etc. directories and merges them for you with the existing ones. If the directory structure of your icon package is different, just modify the first argument to cp.

weibeld
  • 13,643
  • 2
  • 36
  • 50
0

Simplest and Fastest way is just copy paste all in one shot only if you have image in already formatted folder as mentioned below.

  • Download any image from Meterial Icons here

  • Downloaded folder contains all levels of drawable folders (mdpi, hdpi, ect..)

  • Just copy all the folders and paste it to res folder, Here the folder is not replacing just the new image will going to add existing image.

Naveen Kumar M
  • 7,497
  • 7
  • 60
  • 74
0

Install Android drawable importer

Follow this CompleteVideoTutorial for Installing Android drawable importer and Trick to import drawable very fast

Sunil
  • 3,785
  • 1
  • 32
  • 43
0

From Android studio -> Goto Configure->plugins. Search for "Batch Drawable importer" . Click Install. Then restart android studio.

akshaypmurgod
  • 77
  • 1
  • 3
0

I found the easiest way is to just copy the files or in the case of a launcher icon set the folders. Copy folders

And just paste them to the res folder in AndroidStudio.

[Paste in AndriodStudio[2]

Worked great for me.

Itamar Kerbel
  • 2,508
  • 1
  • 22
  • 29