Add Image in Android Studio Using Image Asset Studio

In this post, we are going to learn about how to add image in android studio using image asset studio with example. We will see how to
– add image, stored locally in device, in android studio.
– add predefined images (Clip Art), free for use in app under apache license 2.0
– add text, what-ever text you like, as image source

Getting Started

Have you ever faced situation where you need image(s) while developing any android application ?

That too, multiple images of different resolutions to support multiple screen devices.

Android Studio has implemented a very nice feature to create images – Image Asset Studio.

Using Image Asset Studio, you can include image with various resolutions in your android project. It contains set of images (Above 500). You can choose any image of your choice and include it in your project.

We will create a android project, then create an image using android image asset studio and use it in imageView in project.

So, let’s start now

Create New Project

At first, follow steps below to create new project.

Step Description
1. Open Android Studio (Ignore if already done).
2. Go to File => New => New Project. This will open a new window. Then, under Phone and Tablet section, select Empty Activity. Then, click Next.
3. In next screen, select project name as ImageAssetExample. Then, fill other required details.
4. Then, clicking on Finish button creates new project.

Newbie in Android ?

Some very important concepts (Recommended to learn before you move ahead)

Add Image in XML file

Till now, we have created new android project. Now, open activity_main.xml file. Then, add image into it. Finally, this file will be like –

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/image_example"
        android:src=""
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Note that android:src=”” attribute is left blank. We have done it intentionally. Our target is to add image into drawable folder, then use that image into android:src=”” attribute.

Adding Image in Drawable Folder Using Image Asset Studio

Follow step below to add image –

  1. Select res/drawable folder. Then, right click on it. Then, select New => Image Asset. Check below image –
    Tutorialwing Android Kotlin Add Image in drawable Using Image Asset Studio With Example
  2. Clicking on Image Asset opens Image Asset Studio.
  3. In Image Asset Studio, there are few options which we need to select –
    • Icon Type: There are several icon types –
      1. Launcher Icon (Adaptive and Legacy): Launcher icon for app supporting Android 8.0
      2. Launcher Icon (Legacy only): Launcher icon for app support no higher than Android 7.1
      3. Action Bar and Tab Icons: If we want to create icons for Action Bar or tab
      4. Notification Icons: If we want to create notification icon.
      5. TV Banners: If we want to create banners for TV.
      6. TV Channel Icons: If we want to create TV Channel Icons.

      Note: Here, we have selected Action Bar and Tab Icons.

    • Name: It is name of the image which we want to use for selected image. Here, we have written ic_bluetooth_car.
    • Asset Type: There are three types –
      1. Image: If you have an existing image, choose this type and select path of the image, where it is stored in your device.
      2. Clip Art: If you want to use existing icons (there are over 500 icons), select this type. Then, click on icons being shown after Clip Art. It will open new popup. We can see several icons which can be used for free. Select any image of your choice.
      3. Text: If you want to write some text and use it as image source, you can also do so. Select this type. Then, write text in placeholder provided. You can also select font if you want to change it.

      Here, we have selected Clip Art. Then, selected below image by clicking on icon shown after this option. Check below image for reference –
      Tutorialwing Android Kotlin Clip Art Image Asset Studio select image in drawable

    • Trim: Select Yes or No based on your choice. Note: We have selected No
    • Padding: Add padding if you need some padding around icon. Note: We have selected 0% as padding.
    • Theme: There are three options –
      1. HOLO_DARK: Choose if you want to create image for dark theme.
      2. HOLO_LIGHT: Choose if you want to create image for light theme.
      3. CUSTOM: Choose if you want to apply your own theme. If you choose this, you will see option to choose different colour. Select colour of your own choice.

      Note: We have selected HOLO_LIGHT.

  4. Let’s see a snapshot of what we have selected till now. –
    Tutorialwing Android Kotlin Clip Art Image Asset Studio select image in drawable
  5. Now, clicking on Next button redirects you to next screen as shown below –
    Tutorialwing Android Kotlin Image Asset Selecting Icon Path for image
    In this screen, we need to select Res Directory and Output Directories.

    • Res Directory: We need to select resource source where we want to add the image asset. It is basically related to build variant, including debug or release. There are three available options –
      1. main: Choose this option if you want to add image for all build variant, including debug and release.
      2. debug: Choose this option if you want to add image for debug build only.
      3. release: Choose this option if you want to add image for release build only.

      Note: We have select main here because we want to add image for all build variant.

    • Output Directories It shows final images that will be created. Also, it shows where they will be stored etc.
      Note: In our case, Image are being created for many resolutions. For example, mdpi, hdpi, xhdpi, xxhdpi etc.
  6. Now, click on Finish button. This action creates images for different resolutions and store it in specified path.
  7. Open specified paths. You will see image there. In our case, It’s like image shown below –
    Tutorialwing Android Kotlin Clip Art Image Asset Studio select image in drawable

Using Added Image in Project

Till now, we have added image in drawable folder using image asset studio. Now, we will use them in our project.
So, open activity_main.xml file. Now, add src attribute in ImageView as @drawable/ic_bluetooth_car.

Finally, activity_main.xml file, will look like below –

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/image_example"
        android:src="@drawable/ic_bluetooth_car"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Similarly, you can add any image to ImageView.

Adding String in strings.xml file

Open res/values/strings.xml file. Then, add below code in it –

<resources>
    <string name="app_name">ImageAssetExample</string>
    <string name="image_example">Image Example</string>
</resources>

Now, run your application. You will get output as below –
Tutorialwing Android Kotlin Add Image in Android Studio Using Image Asset With Example

That’s it. We have successfully added image in android studio using image asset studio. If you want to know more, visit here

Leave a Reply