Fast ways to import drawables in Android Studio?

£可爱£侵袭症+ 提交于 2019-11-27 01:06:34

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

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.

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

Pedro Varela

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.

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.

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.

  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.

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!

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

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.

Pedro Varela

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.

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.

Install Android drawable importer

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

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

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

And just paste them to the res folder in AndroidStudio.

[

Worked great for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!