How to create a rounded corners Button in Android Studio Step by Step
In order, to create a rounded shape button, follow below steps:
Video Tutorial:
STEP 1: Open Android Studio
Video Tutorial:
STEP 1: Open Android Studio
STEP 2: Click on "File>New>Create New Project.
STEP 3: In res>layout>activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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:layout_height="match_parent" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:padding="15dp" android:gravity="center" > <Button android:layout_width="300dp" android:layout_height="wrap_content" android:text="Rounded Button" android:textColor="#ffffff" android:background="@color/buttons" /> </LinearLayout> </android.support.constraint.ConstraintLayout>
STEP 4: Create rounded_button.xml in res>drawable
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle" > <solid android:color="#000000"/> <corners android:radius="150dp" /> <stroke android:width="5px" android:color="#098" /> </shape> </item> </selector>
STEP 5: res>value>colors.xml
<?xml version="1.0" encoding="utf-8"?><resources> <color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color> <color name="buttons">@drawable/rounded_button</color> </resources>
Comments
Post a Comment