Open In App
Related Articles

How to Create Drawable Resource XML File in Android Studio?

Improve Article
Save Article
Like Article

Prerequisite: Android Project folder Structure

A drawable resource is a common concept for a graphic that can be drawn to the screen and which one can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon. There are several different types of drawable resources files and let’s discuss all the types in a tabular manner.

Drawable Resources Files


Bitmap File A bitmap graphic file. Android supports bitmap files in three formats: .png, .jpg, .gif.
Nine-Patch File A PNG file with stretchable regions to allow image resizing based on content (.9.png)
State List An XML file that references different bitmap graphics for different states (for example, to use a different image when a button is pressed)
Layer List A Drawable that manages an array of other Drawables. These are drawn in array order, so the element with the largest index is be drawn on top.
Level List An XML file that defines a drawable that manages a number of alternate Drawables, each assigned a maximum numerical value.
Transition Drawable An XML file that defines a drawable that can cross-fade between two drawable resources.
Clip Drawable An XML file that defines a drawable that clips another Drawable based on this Drawable’s current level value.
Inset Drawable An XML file that defines a drawable that insets another drawable by a specified distance. This is useful when a View needs a background drawable that is smaller than the View’s actual bounds.
Scale Drawable An XML file that defines a drawable that changes the size of another Drawable based on its current level value. 
Shape Drawable An XML file that defines a geometric shape, including colors and gradients.

As it is known to all that Android Studio is the official integrated development environment for Google’s Android operating system, built on JetBrains’ IntelliJ IDEA software and designed specifically for Android development. So as a beginner in android app development, the developer should know about the tools vividly before building some awesome projects in Android. So in this article let’s learn to create a drawable resource XML file in Android Studio. Drawable Resource XML is mostly created in the drawable folder and is used in Android to add more customization for views. Here is the step by step process to create a new Drawable Resource XML in Android Studio.

Step by Step Process to Create a New Drawable Resource XML in Android Studio

Step 1: Go to the app > res > drawable and right-click on it. Please refer to the screenshot below to get a clear cut view of the steps.

Step 1

Step 2: After right-clicking on the drawable file go to New > Drawable resource file as shown in the figure below.

Step 2

Step 3: When you click on the Drawable resource file a dialog box will open on your compute screen. Enter the file name in the text box and then click on OK.

Note: File names must start with a lowercase letter.

Step 3

Step 4: After that the drawable resource XML file will be created and one can find the file in app > res > drawable as shown in the figure below. In this case, we have named the file as round_button as shown in the above image.

Step 4

Step 5: Now click on the file name and one can customize the views by writing the necessary codes inside this file.

Step 5

After doing all the steps the important questions arise are why to create a drawable resource XML file in Android? What’s its application? To get the answer to these questions please refer to this article to get a clear-cut idea about its real usage.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 06 Mar, 2022
Like Article
Save Article
Similar Reads