The Wayback Machine - https://web.archive.org/web/20240602014012/https://www.geeksforgeeks.org/how-to-create-drawable-resource-xml-file-in-android-studio/
Open In App

How to Create Drawable Resource XML File in Android Studio?

Last Updated : 06 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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 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.


Previous Article
Next Article

Similar Reads

How to Convert SVG, PSD Images to Vector Drawable File in Android Studio?
In order to use the SVG (Scalable Vector Graphics) or PSD (Photoshop document) image file in your android studio project, you have to first convert them into an XML (Vector Drawable) file. Why XML (Vector Drawable) file? small in sizescalability (It scaled without loss of display quality)height and width can be changed easilysupport transparencycol
3 min read
How to Add Image to Drawable Folder in Android Studio?
The resource folder is the most important folder because it contains all the non-code sources like images, XML layouts, UI strings for the android application. In Android Studio inside the res folder, one can find the drawable folder, layout folder, mipmap folder, values folder, etc. Among them, the drawable folder contains the different types of i
3 min read
How to Add Resource File in Existing Android Project in Android Studio?
Android resource file is a file that stores resources needed for the UI part of an android application. Like: Layout files, drawable files, etc. In the android application, it is very often that we need another resource file for another purpose in the existing application. There are many types of resource files Layout files, Drawables, Menus are so
1 min read
How to Add Text Drawable to ImageView in Android?
In many android apps, you will get to see a feature in which you can see a simple text is displayed inside an ImageView or you can get to see that a text is displayed in a specific image or a shape. Mostly this type of view is seen in the Contacts application which is present on your Android device. In that app, you will get to see the first letter
5 min read
How to Display a Drawable Inside a Button in Android?
A Button in Android is basically a subclass of TextView, which lets the user press or click it to perform an action. Buttons generally contain text that lets the user understand the action property of the button. Sometimes, an ImageView can also be used as a button if the developer wishes to display an image rather than some text. But some buttons
3 min read
How to Convert Drawable to Bitmap in Android using Jetpack Compose?
A drawable is an image file that is used to display inside our image view. We can display the images directly within the image view from our drawable folder. Images can be displayed within our image view directly in the form of the image file or a bitmap format. In this article, we will take a look at How to Convert Drawable to Bitmap in Android us
7 min read
How to Set Background Drawable Programmatically in Android?
In many android applications, we can get to see that the background color of this application changes dynamically when updated from the server. For updating this color we have to set the background color of our layout programmatically. In this article, we will take a look at How to Set Background Drawable Programmatically in an Android application.
3 min read
How to fix "Android Studio doesn't see device" in Android Studio?
In Android Studio, sometimes the list of devices and emulators doesn't list your physical device when you try to plug it in. Or you may have faced a situation when you plugged the phone in for the first time, no dialog appeared asking if you trust the computer. But the laptop is already allowed to connect to the mobile device. However, the button R
4 min read
How to Fix "Android studio logcat nothing to show" in Android Studio?
Logcat Window is the place where various messages can be printed when an application runs. Suppose, you are running your application and the program crashes, unfortunately. Then, Logcat Window is going to help you to debug the output by collecting and viewing all the messages that your emulator throws. So, this is a very useful component for the ap
2 min read
How to Get Resource Name From Resource ID in Android?
In Android, the resource name is the name assigned to a resource while declaring it in the code or in the XML. The resource name is of format: [<package_name>.]R.<resource_type>.<resource_name> where <package_name> is the name of the package where the resource is stored<resource_type> is R subclass for the type of reso
3 min read
Article Tags :