Fast ways to import drawables in Android Studio?

AndroidAndroid StudioAndroid Resources

Android Problem Overview


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).

Android Solutions


Solution 1 - Android

Solution 2 - Android

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 manager1

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.

Solution 3 - Android

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.

Solution 4 - Android

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.

Solution 5 - Android

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!

Solution 6 - Android

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.

Solution 7 - Android

  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.

Solution 8 - Android

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.

Solution 9 - Android

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

Solution 10 - Android

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.

Solution 11 - Android

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.

Solution 12 - Android

Install Android drawable importer

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

Solution 13 - Android

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

Solution 14 - Android

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 AndriodStudio2

Worked great for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnatarioView Question on Stackoverflow
Solution 1 - AndroidCoolView Answer on Stackoverflow
Solution 2 - AndroidWirlingView Answer on Stackoverflow
Solution 3 - AndroidPedro VarelaView Answer on Stackoverflow
Solution 4 - AndroidmannykaryView Answer on Stackoverflow
Solution 5 - AndroidAppersideView Answer on Stackoverflow
Solution 6 - AndroidweibeldView Answer on Stackoverflow
Solution 7 - AndroidCalView Answer on Stackoverflow
Solution 8 - AndroidPedro VarelaView Answer on Stackoverflow
Solution 9 - AndroidVishal KumarView Answer on Stackoverflow
Solution 10 - AndroidweibeldView Answer on Stackoverflow
Solution 11 - AndroidNaveen Kumar MView Answer on Stackoverflow
Solution 12 - AndroidSunilView Answer on Stackoverflow
Solution 13 - AndroidakshaypmurgodView Answer on Stackoverflow
Solution 14 - AndroidItamar KerbelView Answer on Stackoverflow