Custom Buttons in Android
Two shapes we will see in this Tutorial.1. Rounded Corner Button2. Circle Shape Button.
First of all, we will see how to create rounded corner Button
Step 1: After creating Android Project create XML file under res => drawable folder and give a name rounded_corner_bg.xml and paste below code.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<!-- you can use any color you want -->
<solid android:color="#00BCD4"/>
<corners android:radius="40dp"/>
</shape>
Step 2: Open activity_main.xml file and paste below code
<LinearLayout 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:gravity="center"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="300dp"
android:layout_height="70dp"
android:text="Button"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#ffffff"
android:background="@drawable/rounded_corner_bg"/>
</LinearLayout>
wohho done!!! π...you will see the following shape .
So we are done with the first shape. Now let's proceed for the next shape i.e Circle shape Button
Step 1: Create XML file under res => drawable folder and give a name circle_shape_bg.xml and paste below code.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#87CEEB"/>
<size android:width="250dp" android:height="250dp"/>
</shape>
</item>
</selector>
Step 2: Open activity_main.xml file and paste below code
<LinearLayout 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:gravity="center"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#ffffff"
android:background="@drawable/circle_shape_bg"/>
</LinearLayout>
wohho done!!! π...you will see the following shape .
Thank You.✌
Nice...ππ
ReplyDeleteππ
ReplyDeleteππΆ
ReplyDeleteGreat π
ReplyDeleteNice... ��
ReplyDeleteThnq
DeleteEasy and awesome tutorials
ReplyDeleteThnq dea
DeleteSimple to understand the steps mam..thank u.
ReplyDeleteThnq sir
DeleteEasy to understand
ReplyDeleteGreatπ
ReplyDeleteThank you for the round button,it was a very helpfulππ
ReplyDeleteπ
DeleteSimple to learn.
ReplyDeleteThank you mam
Simple and easy to understand.
ReplyDeleteButton with different shapes became much easier thankyou!
Concise and understandable
ReplyDeleteEasy to understand ��
ReplyDeleteVery nice and useful ..thanx fr this amzg postπ
ReplyDeleteGreat
ReplyDeleteWow great
ReplyDeleteNicely explained
ReplyDeleteNice
ReplyDeleteNice
ReplyDeleteEasy To understand..π
ReplyDelete