Creating Basic Custom Button:
To make a custom Button, we will create a new XML file "button_bg" in our drawable folder. This file will act as background source of our button. Let's get started :
button_bg.xml :
Now in your activity_main.xml use this as background :To make a custom Button, we will create a new XML file "button_bg" in our drawable folder. This file will act as background source of our button. Let's get started :
button_bg.xml :
1 2 3 4 5 6 7 8 | <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@android:color/holo_blue_dark" /> <corners android:radius="25dp" /> <stroke android:color="@android:color/holo_blue_bright" android:width="2dp" /> </shape> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" tools:context=".MainActivity"> <Button android:gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is a Custom Button" android:padding="10dp" android:textColor="@android:color/white" android:background="@drawable/button_bg" android:layout_centerInParent="true"/> </RelativeLayout> |
ScreenShot :
No comments:
Post a Comment