How To Add Images In Android Studio Drawable Folder

When develop android application, you always need to add images in it. This article will show you how to add images in your android application, there is also an example which will show you how to load and use the added images.

Images in android application are commonly saved in android project drawable folder. After that, android studio will generate an drawable id for each added image in R class. Then you can use R.drawable.imageId to refer that image in your java code.

How To Add Images To Drawable Folder In Android Studio ?

  1. Launch android studio, go to project view in left panel. If you can not find project view then you can click ” View —> Tool Windows —> Project ” to show the project view in left panel.
    click android studio view tool windows project menu
  2. In project view, select Android sub view in sub view drop down list.
    android studio project view android sub view
  3. Then you can see drawable folder under app —> res folder in below panel.
    android project view android sub view app res drawable folder
  4. Copy images from any directory you saved and right click the drawable folder, click Paste menu in popup menu list then accept all popup dialog. After that you can see the images added in the drawable folder.
    android project view android sub view paste images to drawable folder
  5. Please Note the image name can only include lowercase a-z, 0-9, or underscore, otherwise there will have an error when you rebuild the android project. The error message like ” Error: ‘-‘ is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore
    android drawable image name format error
  6. You can right click the image, click ” Refactor —> Rename ” to update the image name to an legal name.

How To Use Images In Android Application ?

After add images in drawable folder, you can use them in your android application java code. Below is an example.

  1. There are 6 images in it, when application start, it will show image1.png.
  2. When you click the image, it will show another image in order.

add images in android drawable folder execution example

You can read Android Hello World Example Project File Structure to learn android project structure and core files introduction if you do not know before.

This example’s core files are AndroidManifest.xmlShowImageActivity.javaactivity_show_image.xml.

how to add images in drawable folder core files

1. AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""

        <activity android:name="com.dev2qa.example.image.ShowImageActivity">
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />



package com.dev2qa.example.image;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class ShowImageActivity extends AppCompatActivity {

    // This int array is used to store image resource that will be used.
    int imagesIdArr[] = new int[]{R.drawable.img1, R.drawable.img2, R.drawable.img3, R.drawable.img4, R.drawable.img5, R.drawable.img6};

    // Current displayed image index in above images array, initial value is 0..
    int currImage = 0;

    protected void onCreate(Bundle savedInstanceState) {

        // Get layout object to add ImageView object,
        // idShowImageLayout is a LinearLayout object defined in res / layout / activity_show_image.xml
        LinearLayout showImageLayoutView = (LinearLayout)this.findViewById(;

        // Create an ImageView object.
        final ImageView imgView = new ImageView(this);

        // Add ImageView into LinearLayout object.

        // Show the first image in imagesIdArr array.

        // Register an OnClickListener for image view object.
                new View.OnClickListener() {
                    // When click image, this method will be triggered.
                    public void onClick(View view) {
                        // If currrImage
                            currImage = -1;

3. activity_show_image.xml

<?xml version="1.0" encoding="utf-8"?>
< xmlns:android=""



Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.