398

I need to add an image to the res/drawable folder...

When I choose new > Image Asset, it comes out a dialog to choose Asset Type...

How can I add an image to res/drawable folder?

live-love
  • 48,840
  • 22
  • 240
  • 204
Alan W.
  • 4,566
  • 2
  • 15
  • 26
  • 5
    Why is it a problem if it is inside the `mipmap` folder? You just need to access it va `R.mipmap.[...]` rather than `R.drawable.[...]` Also, you can drag and drop images directly into the `drawable` folder in Android Studio - just make sure that your Project Structure is set to `Project`, and not `Android`, at the top left of the screen. – PPartisan Mar 14 '15 at 11:05
  • 7
    Android Studio uses mipmap folder to load launcher icon in project. as android says **It's best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions different from the device's current density. For example, an xxxhdpi app icon can be used on the launcher for an xxhdpi device.** take a look at this answer http://stackoverflow.com/a/24066445/1576416 – Amrut Bidri Mar 14 '15 at 11:30
  • See 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:13
  • Hi Alan! As you can see my answer to this question is recommanded as a better one by comments and number of votes. You can accept it as the best answer if you think so too. – Chris Nov 25 '15 at 17:33
  • simply drag and drop to drawable folder – kritika Aug 06 '15 at 13:11
  • @kritika - I'm using Android Studio 3.0. It is not allowing me to drag and drop image files on `drawable` folder. It seems this behavior has changed in later versions. – RBT Dec 31 '19 at 01:40
  • Related post - [Android splash screen image sizes to fit all devices](https://stackoverflow.com/q/10574363/465053) – RBT Jan 04 '20 at 01:51

23 Answers23

425

For Android Studio 1.5:

  1. Right click on res -> new -> Image Asset
  2. On Asset type choose Action Bar and Tab Icons
  3. Choose the image path
  4. Give your image a name in Resource name
  5. Next->Finish

Update for Android Studio 2.2:

  1. Right click on res -> new -> Image Asset

  2. On Icon Type choose Action Bar and Tab Icons

  3. On Asset type choose Image

  4. On Path choose your image path

  5. Next->Finish

The image will be saved in the /res/drawable folder.

Warning! If you choose to use images other than icons in SVG or PNG be aware that it could turn grey if the image is not transparent. You can find an answer in comments for this problem but none of these are verified by me because I never encountered this problem. I suggest you to use icons from here: Material icons

RBT
  • 24,161
  • 21
  • 159
  • 240
Chris
  • 6,105
  • 6
  • 38
  • 55
  • 12
    Hi. I followed the steps and it did save the image in that drawable folder. Now in my case, I´m not able to see the image preview the wizard presents when doing those steps. Anyone had that same problem? – Fergara Dec 23 '15 at 16:52
  • @Fergara Try Invalidate Caches / Restart from File menu. If the problem persists open a new question. Maybe someone faced the same problem. – Chris Dec 23 '15 at 17:32
  • 10
    @Cristi This didn't work for me because a lot of the details of the image were [stripped away](http://stackoverflow.com/questions/34860702/image-getting-destroyed-when-being-put-in-drawables-folder#34860702) – Foobar Jan 18 '16 at 18:28
  • 2
    It doesn't work correctly for me either. A portion of the edge (all sides) are cropped out, and the image itself is re-sampled considerably. Android Studio 1.5.1 – SikoSoft Jan 18 '16 at 20:35
  • 387
    This just doesn't work. The resulting images are just useless gray shapes. – markj Feb 18 '16 at 11:21
  • 10
    Unless you are going to add to actionbar and it turns grey. Use as a launcher icon – Faisal Naseer May 24 '16 at 17:58
  • @bradley4 It seems that the color problem appears only to some developers. I think it is from the size of the icon. Choosing Launcher Icons will put the icons in the wrong folder, not drawable. A similar problem about the grey background is discussed here: http://stackoverflow.com/questions/28807121/android-icon-generator-for-actionbar-and-notification-not-working-grey-shape and more info about icons size here http://iconhandbook.co.uk/reference/chart/android/ – Chris Sep 15 '16 at 07:38
  • 1
    @markj is right. This method will change the icon color. Relevant information can be found at http://stackoverflow.com/questions/41011070/how-to-set-the-color-of-icon-in-android-toolbar. – Lawrence Teo Dec 13 '16 at 09:30
  • This doesn't works for raw images (not added as icons). See here http://stackoverflow.com/questions/34367464/android-when-attempting-to-add-an-image-creates-a-blank-image –  Jan 05 '17 at 03:54
  • 4
    In case someone checked this response, the image should be transparent to fix the gray issue – Jek Apr 05 '17 at 16:04
  • 21
    I think it's really strange that a regular image is categorised in Action Bar and Tab Icons. – Erik Aug 06 '17 at 09:30
  • 6
    This just doesn't work. The resulting images are just useless gray shapes. +1 – marti_ Dec 21 '17 at 20:31
  • @Osgux https://stackoverflow.com/questions/29047902/how-to-add-an-image-to-the-drawable-folder-in-android-studio/31069202?noredirect=1#comment73542663_31069202 – Chris Dec 22 '17 at 15:19
  • 1
    Thanks! I saw a video when only copy the image to drawable it was really easy – marti_ Dec 22 '17 at 16:52
  • So if you copy-pasted your pngs into your res directory, delete copy-pasta files and just do this solution instead. Worked like a charm, thank you very much! – NekoKikoushi Mar 12 '18 at 21:58
  • @Osgux can u share the video – iosMentalist Apr 16 '18 at 15:27
  • 7
    Why is dealing with images in Android still a nightmare? It's 2019! – Malfunction Sep 28 '19 at 13:14
192

For Android Studio 3.4+:

You can use the new Resource Manager tab Click on the + sign and select Import Drawables.

From here, you can select multiple folders/files and it will handle everything for you.

Resource Manager

The result will look something like this:

Resource Manager Picker

Click the import button and the images will be automatically imported to the correct folder.

RBT
  • 24,161
  • 21
  • 159
  • 240
Leosan
  • 2,584
  • 1
  • 14
  • 17
  • 2
    @abdu you can find about more at https://developer.android.com/studio/write/resource-manager – Leosan Sep 04 '19 at 10:42
  • 4
    This answer was the most beneficial for me as a new android developer using version 3.5.3 – JoJo Jan 11 '20 at 12:26
  • 2
    This is a great method, however the Next button in the wizard does nothing. Even when importing a single image the wizard will not continue past the first screen. – apsommer Aug 04 '20 at 01:26
  • Never knew about this. Finally a better way to handle resource files in general. Thanks! – Andrew May 28 '21 at 17:44
  • Where is Resource manager located though? – GeneCode Nov 24 '21 at 11:06
  • @GeneCode you can find it in the left tabs in Android Studio, if you read one of the previous comments you can see there's a link detailing everything about the Resource Manager. – Leosan Nov 25 '21 at 13:11
  • If the Resource Manager would work reliably this would be the way to go, but maybe that's just the case for me (using v2021.3.1) – Rocco Nov 16 '22 at 13:31
176

Copy *.png image and paste to drawable folder.

After adding the image, you can use the added image asset in code:

You can either add image by using xml file

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/image_name" /> 

OR You can set image by using program:

ImageView iv = (ImageView)findViewById(v);  
iv.setImageResource(R.drawable.image_name);
RBT
  • 24,161
  • 21
  • 159
  • 240
Arshid KV
  • 9,631
  • 3
  • 35
  • 36
  • 8
    but that still doesnt solve the problem. The question here is about the mage truning grey or blank. When you copy the mage in the folder directly the image re-sizing is not done – timberlake May 29 '15 at 10:42
  • 1
    you shouldnt have to resize the image ..android studio does it for you and puts it in various folders accordingly – timberlake May 29 '15 at 18:21
  • I think you have to change to "project view mode", and then create a drawable-hdpi folder under res folder. Then, if you change to "android view mode" and try to paste a resource in drawable folder, ask you about where to put the image (I choose always drawable-hdpi) – Terranology Nov 11 '16 at 11:23
  • @Terranology No need to create the folder first. It will create the folder if it does not exist. See [Kundan's answer](http://stackoverflow.com/a/33007226/4515489). – jk7 Mar 13 '17 at 21:03
  • can u explain what is v inside findViewById(v); in ImageView iv = (ImageView)findViewById(v); – Agent 0 Feb 10 '18 at 23:41
72

Do it through the way Android Studio provided to you

Right click on the res folder and add your image as Image Assets in this way. Android studio will automatically generate image assets with different resolutions.

You can directly create the folder and drag image inside but you won't have the different sized icons if you do that.

enter image description here

Community
  • 1
  • 1
Fangming
  • 24,551
  • 6
  • 100
  • 90
60

For Example, I've to add list.png in drawable folder..

enter image description here

And now I'll paste it in drawable folder. Alternatively you can do it Ctrl + C/V, as we programmers do it. :)

enter image description here

RBT
  • 24,161
  • 21
  • 159
  • 240
Saim Mehmood
  • 783
  • 8
  • 14
54

It's very simple. Just copy your image and paste it in the drawable folder. One more thing. When you paste an image in the drawable folder, a popup window will appear asking for a folder name. Add xxhdpi,xhdpi,hdpi or mdpi according to your image, like in the image below:enter image description here

If you are still having problems, check out this link: Drawable folder in android studio

StephenA
  • 61
  • 6
kundan roy
  • 1,936
  • 1
  • 18
  • 21
22

You can just copy and paste an image file(.jpg at least) into your res/drawable. It worked for me!

user1321759
  • 1,734
  • 2
  • 14
  • 11
16
  1. Open your project in Android Studio

  2. Click on res

  3. Right click on drawable

  4. Click on Show in Explorer

  5. Double click on drawable folder.

  6. Copy your image file in it and rename as your wish.

  7. Now write your image file name after @drawable/ .

It will show the image you've selected.

Spikatrix
  • 20,225
  • 7
  • 37
  • 83
Matrixx
  • 153
  • 2
  • 6
12

Install and use the Android Drawable Importer plugin:

https://github.com/winterDroid/android-drawable-importer-intellij-plugin

Instructions on how to install the plugin are on that page. It's called "Android Drawable Importer" in the plugin search results.

Once installed:

  1. right click on "res" folder and select New -> Batch Drawable Import
  2. hit the + and select your source image
  3. choose what resolution you want it considered and which other sizes to auto-generate for

Seems kind of ridiculous that Android Studio doesn't support this directly.

EDIT: But Xcode doesn't either so.... :-(

David K. Hess
  • 16,632
  • 2
  • 49
  • 73
9

You need to use a third party plugin like AndroidIcons Drawable Import to install this. Goto Android Studio > Prefrences > Plugins > and browse for AndroidIcons Drawable You can do things like

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

Restart android studio. If you do not have the drawables folder created, create it by importing any image as -"Action Bar and Tab Icons" & "Notification Icons",. Then right clink on the file explorer and you can see 4 options in the new tab. Use any one according to your need.

timberlake
  • 777
  • 6
  • 13
9

Android Studio 3.0:

1) Right click directory 'drawable'.
2) Click on: Show in Explorer

Now you have an explorer opent with a few directories in it, one of then is 'drawable'.

3) Go in the directory 'drawable'.
4) Place the image you want in there.
5) Close the explorer again.

Now the image is in Android Studio under 'res/drawable'.

Tenzin
  • 2,415
  • 2
  • 23
  • 36
5

Simplest way is to just drag and drop the image into the drawable folder. The important thing to keep in mind if you are using Android Studio 2.2.x version make sure you are in PROJECT VIEW else it will not allow to drag and drop the image.

enter image description here

Shivaraj Nesargi
  • 129
  • 2
  • 12
5

Tutorial Source Link

Android Studio 3.2

Blazingly fast :P

enter image description here

Just Copy and Paste in this folder

Code Spy
  • 9,626
  • 4
  • 66
  • 46
4

My way of exporting/importing image assets. I use Sketch design.

Step 1. Sketch: export using Android preset

Sketch

Step 2. Finder: Go to the export folder > Cmd+C Finder

Step 3. Finder: Go to your project's /res folder > Cmd+V > Apply to all > Merge Finder

OK, the images are in your project now.

SoftDesigner
  • 5,640
  • 3
  • 58
  • 47
1

Its quite simple

1) just copy your images and paste in drawable folder.

2) when you paste image(for eg"mdpi) in drawable folder a popup window will appear asking folder name add -mdpi .

3)Do it for all(hdpi,xhdpi,xxhdpi).

I just added one link that you can check out if have any doubt.

http://www.androidwarriors.com/2015/07/android-studio-drawable-folders.html

STS
  • 1,195
  • 1
  • 8
  • 11
0

In Android Studio, you can go through following steps to add an image to drawable folder:

  1. Right click on drawable folder
  2. Select Show on Explorer
  3. Paste image you want to add
gokyori
  • 357
  • 4
  • 15
0

Just copy your images and select drawable then on the option of Paste or press shortcut ctrl v. images are added

0

go to
https://hotpot.ai/icon-resizer and resize your stock png(!) image to a batch as zip. Put e.g. _ before their names ( otherwise it seems wont be accepted by A S (who knows why) )

Then go to AS's Resource Manager on the left panel and then hit + on its top-left and import images you've gotten one-by-one. Dont use unofficial plug-ins.

CodeToLife
  • 3,672
  • 2
  • 41
  • 29
-1

Example without any XML

Put your image image_name.jpg into res/drawable/image_name.jpg and use:

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;

public class Main extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final ImageView imageView = new ImageView(this);
        imageView.setImageResource(R.drawable.image_name);
        setContentView(imageView);
    }
}

Tested on Android 22.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
-1

Copy the image then paste it to drawables in the resource folder of you project in android studio.Make sure the name of your image is not too long and does not have any spacial characters.Then click SRC(source) under properties and look for your image click on it then it will automatically get imported to you image view on you emulator.

-1

Adding images to the drawable folder is pretty simple. Just follow these steps:

  1. Download the required image and save it on desktop.
  2. Now, go to Android Studio and right click on drawable inside res.
  3. On right clicking you will see 'Show in Explorer' or 'Reveal in Finder'.
  4. Click on 'Show in Explorer' or 'Reveal in Finder' and then drag or simply copy your downloaded image into drawable folder.

Your image will be saved inside drawable and you can use it.

-3

new > image asset > asset TYPE. works for me very well. thanks.

Davi
  • 1
  • 1
-6

In Android Studio

  1. Select Drawable folder, do Ctrl N Screenshot
  2. Select Image asset

  3. Select Action Bar & Tab icons in asset type

  4. Click Next

  5. Select size

  6. You're done!

Scrooge
  • 86
  • 7