Skip to content
Related Articles

Related Articles

How to Create Drawable Resource XML File in Android Studio?
  • Last Updated : 18 Feb, 2021
GeeksforGeeks - Summer Carnival Banner

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

Description

Bitmap FileA bitmap graphic file. Android supports bitmap files in three formats: .png, .jpg, .gif.
Nine-Patch FileA PNG file with stretchable regions to allow image resizing based on content (.9.png)
State ListAn XML file that references different bitmap graphics for different states (for example, to use a different image when a button is pressed)
Layer ListA 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 ListAn XML file that defines a drawable that manages a number of alternate Drawables, each assigned a maximum numerical value.
Transition DrawableAn XML file that defines a drawable that can cross-fade between two drawable resources.
Clip DrawableAn XML file that defines a drawable that clips another Drawable based on this Drawable’s current level value.
Inset DrawableAn 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 DrawableAn XML file that defines a drawable that changes the size of another Drawable based on its current level value. 
Shape DrawableAn 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 Andoird? 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.

Want a more fast-paced & competitive environment to learn the fundamentals of Android?
Click here to head to a guide uniquely curated by our experts with the aim to make you industry ready in no time!
My Personal Notes arrow_drop_up
Recommended Articles
Page :