This article explains how to design a button using drawable.
Android provides many drawable resources. In this, we use only a shape darwable resource. A drawable shape provides many basic shapes, such as Rectangle, Oval, Ring, Line. Form these shapes you can create many effects. All of these shapes support the following tags.
- gradient: used for gradient background
- size: used to give the size to the shapes
- stroke: used to give a stroke to the shapes
-
solid: used to give solid background-color
- padding: used to give padding to the shapes
Step 1
Create a project like this:
Step 2
Create an XML file and write the following.
In this, I have taken multiple buttons inside a linear layout and I have given the shape and color through the drawable XML file. This will change the color and shape of the buttons. I set all the backgrounds of all the buttons to a gradient XML file that I have created inside the drawable folder.
I set the gradient2.xml file to the LinearLayout at the bottom that contains a textview.
Step 3
Create an XML file inside a drawable folder and write the following. I hope that you know how to create an XML file inside a drawable folder.
gradient.xml
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="rectangle">
-
- <corners
- android:bottomLeftRadius="10dp"
- android:bottomRightRadius="10dp"
- android:topLeftRadius="10dp"
- android:topRightRadius="10dp"/>
-
- <gradient android:startColor="#1E90FF"
- android:endColor="#1E90FF"/>
-
- </shape>
Step 4
Another XML file inside the drawable folder:
gradient 2.xml
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="rectangle">
- <corners android:bottomLeftRadius="10dp"
- android:bottomRightRadius="10dp"
- android:topLeftRadius="10dp"
- android:topRightRadius="10dp" />
- <gradient android:startColor="#ffffff"
- android:endColor="#ffffff" />
- <stroke android:color="#000000"
- android:width="1dp" />
- </shape>