How to import set of icons into Android Studio project
Asked Answered
O

8

69

I downloaded collection of icons from Android Developers center Each icon in this collection is ordered in forlders according to its resolution: drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi.

Is there a way to import all the 4 icon's files in one action to Android Studio or I need to copy it one by one? (when I used new->Image Asset , I had to fill a file path, I couldn't fill it with folder path)

Update 25/2/15:
According to this SO question, seems like there is a way to generate the 4 size of icons by Android Asset Studio, and then import the zip file directly to your Android Studio project res folder - has anyone used it?

Observatory answered 24/2, 2015 at 16:5 Comment(5)
Man copy it one by one, there's no other way.Estriol
All this concept is unclear to me: for example when I add 'image asset' I can select asset-type and theme - where are these properties saved under the 'src' folder of the project?Observatory
If you import via image asset then your images will be imported in res/drawableEstriol
@Estriol its not always true.In new version of android studio if you import a launcher icon via image asset then it will go in res/mipmap instead.Causalgia
Possible duplicate of Fast ways to import drawables in Android Studio?Orebro
L
140

Edit : After Android Studios 1.5 android support Vector Asset Studio.


Follow this, which says:

To start Vector Asset Studio:

  1. In Android Studio, open an Android app project.
  2. In the Project window, select the Android view.
  3. Right-click the res folder and select New > Vector Asset.

enter image description here


Old Answer

Go to Settings > Plugin > Browse Repository > Search Android Drawable Import

This plugin consists of 4 main features.

  1. AndroidIcons Drawable Import
  2. Material Icons Drawable Import
  3. Scaled Drawable
  4. Multisource-Drawable

How to Use Material Icons Drawable Import : (Android Studio 1.2)

  • Go to File > Setting > Other Settings > Android Drawable Import

enter image description here

  • Download Material Icon and select your downloaded path.

enter image description here

  • Now right click on project , New > Material Icon Import

enter image description here

  • Use your favorite drawable in your project.

enter image description here

Laplante answered 24/2, 2015 at 18:59 Comment(13)
I installed it but can't use it. I have to provide through IDE settings-->Android Drawable Importer - a path to the asset's home folder but there is no way to edit the field to provide this folder path. besides I don't know what's my project's asset's folder. It only have the icons under res\drawable-mdpi, res\drawable-hdpi, etc.Observatory
U have to provide your downloaded icon folder path not your assets folderLaplante
U can download Material Icon from github.com/google/material-design-icons/releases and use downloaded folder pathLaplante
and then what, how do I use this plugin? Right clicking the drawable folder gives me nothing.Prindle
Right Click > New > Select your Configured option for this pluginLaplante
Eventually I figured that it this is what I've been looking for. I am using the option new->scaled drawable that was added by this plugin, in order to import images to Android Studio. Thanks!Observatory
@KishanVaghela can you please explain how to set the path of Material icos root folder for Android Drawable Importer plugin?Lorilee
@KishanVaghela thank you so much for the Edit, it is much more clear and easy now.Lorilee
In Android Studio 1.3 the plugin (as the field Other Settings) doesn't appear under the SettingsFarleigh
@LuciusHipan This screenshots from Android Studio 1.2, If you have Android Studio v1.3 or above you can find from search.Laplante
@Kishan Vaghela, thank you. In Android Studio 1.3 you can simply skip this step. After you download plugin and restart the studio, the plugin appears already in the "New" section (imho it downloads the icons in the runtime)Farleigh
@KishanVaghela Is there a way to get grey icons? I don't want just black and white and lots of the default Android icons are in a dark grey.Ethelinda
In Android Studio 2.2 theres an option to add icons from the icon set. Rightclick the res folder and choose New > Image Asset. You are now in "Asset Studio" where you can simply select a theme and clipart and Bob's your uncle.Redeemer
B
20

Actually if you downloaded the icons pack from the android web site, you will see that you have one folder per resolution named drawable-mdpi etc. Copy all folders into the res (not the drawable) folder in Android Studio. This will automatically make all the different resolution of the icon available.

Botulinus answered 19/9, 2015 at 13:43 Comment(2)
This is the best solution and yet simple. For the icons pack, I generate from makeappicon.comMoffett
For the location C:\Users\<your_username>\AndroidStudioProjects\<your_project_name>\app\src\main\resMoffett
P
9

For custom images you created yourself, you can do without the plugin:

Right click on res folder, selecting New > Image Asset. browse image file. Select the largest image you have.

It will create all densities for you. Make sure you select an original image, not an asset studio image with an alpha, or you will semi-transpartent it twice.

Prindle answered 13/7, 2015 at 7:49 Comment(3)
The Image Asset tool leaves a transparent border around my files, resulting in smaller icons than the rest of the ones on the phone. Have you found a way to mitigate that?Gammy
It does, I asked him to make this padding optional in the next version.Prindle
There is no way to give transparent background in Android Studio 2.0.Elytron
O
1

If for some reason you don't want to use the plugin, then here's the script you can use to copy the resources to your android studio project:

echo "..:: Copying resources ::.."
echo "Enter folder:"
read srcFolder
echo "Enter filename with extension:"
read srcFile
cp /Users/YOUR_USER/Downloads/material-design-icons-master/"$srcFolder"/drawable-xxxhdpi/"$srcFile" /Users/YOUR_USER/AndroidStudioProjects/YOUR_PROJECT/app/src/main/res/drawable-xxxhdpi/"$srcFile"/
echo "xxxhdpi copied"
cp /Users/YOUR_USER/Downloads/material-design-icons-master/"$srcFolder"/drawable-xxhdpi/"$srcFile" /Users/YOUR_USER/AndroidStudioProjects/YOUR_PROJECT/app/src/main/res/drawable-xxhdpi/"$srcFile"/
echo "xxhdpi copied"
cp /Users/YOUR_USER/Downloads/material-design-icons-master/"$srcFolder"/drawable-xhdpi/"$srcFile" /Users/YOUR_USER/AndroidStudioProjects/YOUR_PROJECT/app/src/main/res/drawable-xhdpi/"$srcFile"/
echo "xhdpi copied"
cp /Users/YOUR_USER/Downloads/material-design-icons-master/"$srcFolder"/drawable-hdpi/"$srcFile" /Users/YOUR_USER/AndroidStudioProjects/YOUR_PROJECT/app/src/main/res/drawable-hdpi/"$srcFile"/
echo "hdpi copied"
cp /Users/YOUR_USER/Downloads/material-design-icons-master/"$srcFolder"/drawable-mdpi/"$srcFile" /Users/YOUR_USER/AndroidStudioProjects/YOUR_PROJECT/app/src/main/res/drawable-mdpi/"$srcFile"/
echo "mdpi copied"
Opus answered 18/12, 2015 at 11:38 Comment(0)
U
1

Newer versions of Android support vector graphics, which is preferred over PNG icons. Android Studio 2.1.2 (and probably earlier versions) comes with Vector Asset Studio, which will automatically create PNG files for vector graphics that you add.

The Vector Asset Studio supports importing vector icons from the SDK, as well as your own SVG files.

This article describes Vector Asset Studio: https://developer.android.com/studio/write/vector-asset-studio.html

Summary for how to add a vector graphic with PNG files (partially copied from that URL):

  1. In the Project window, select the Android view.
  2. Right-click the res folder and select New > Vector Asset.
  3. The Material Icon radio button should be selected; then click Choose
  4. Select your icon, tweak any settings you need to tweak, and Finish.
  5. Depending on your settings (see article), PNGs are generated during build at the app/build/generated/res/pngs/debug/ folder.
Unquestioning answered 11/8, 2016 at 19:26 Comment(0)
C
1

just like Gregory Seront said here:

Actually if you downloaded the icons pack from the android web site, you will see that you have one folder per resolution named drawable-mdpi etc. Copy all folders into the res (not the drawable) folder in Android Studio. This will automatically make all the different resolution of the icon available.

but if your not getting the images from a generator site (maybe your UX team provides them), just make sure your folders are named drawable-hdpi, drawable-mdpi, etc. then in mac select all folders by holding shift and then copy them (DO NOT DRAG). Paste the folders into the res folder. android will take care of the rest and copy all drawables into the correct folder.

Copper answered 20/7, 2017 at 3:56 Comment(0)
C
1

Since Android Studio 3.4, there is a new tool called Resource manager. It supports importing many drawables at once (vectors, pngs, ...) . Follow the official documentation.

Court answered 23/11, 2020 at 7:42 Comment(0)
P
0

what u need to do is icons downloaded from material design, open that folder there are lots of icons categories specified, open any of it choose any icon and go to this folder -> drawable-anydpi-v21. this folder contains xml files copy any xml file and paste it to this location -> C:\Users\Username\AndroidStudioProjects\ur project name\app\src\main\res\drawable. That's it !! now you can use the icon in ur project.

Phyllode answered 14/6, 2018 at 2:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.