activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:gravity="center" android:orientation="vertical" tools:context=".MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:background="@drawable/btn_solid_color" android:padding="5dp" android:text="Solid Button" android:textAllCaps="false" android:textColor="#FFFFFF" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:background="@drawable/btn_gradient" android:padding="5dp" android:text="Gradient Button" android:textAllCaps="false" android:textColor="#FFFFFF" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:background="@drawable/btn_center_gradient" android:padding="5dp" android:text="Center Gradient Button" android:textAllCaps="false" android:textColor="#FFFFFF" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:background="@drawable/btn_edge_color" android:padding="5dp" android:text="Edge Color Button" android:textAllCaps="false" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:background="@drawable/btn_round_edge" android:padding="5dp" android:text="Round Edge Button" android:textAllCaps="false" android:textColor="#FFFFFF" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:background="@drawable/btn_oval" android:padding="5dp" android:text="Oval Button" android:textAllCaps="false" android:textColor="#FFFFFF" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:background="@drawable/btn_oval_gradient" android:padding="15dp" android:text="Oval Gradient Button" android:textAllCaps="false" android:textColor="#FFFFFF" /> </LinearLayout> |
MainActivity.kt
1 2 3 4 5 6 7 8 9 10 11 12 |
package com.phaisarn.ktapplication import android.support.v7.app.AppCompatActivity import android.os.Bundle class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } } |
drawable/btn_solid_color.xml
1 2 3 4 |
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:tint="#111"></shape> |
drawable/btn_gradient.xml
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:angle="90" android:endColor="#258191" android:startColor="#44e3ff" /> </shape> |
drawable/btn_center_gradient.xml
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:angle="90" android:centerColor="#12434c" android:endColor="#258191" android:startColor="#44e3ff" /> </shape> |
drawable/btn_edge_color.xml
1 2 3 4 5 6 7 8 9 10 11 |
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:angle="90" android:endColor="#FFFFFF" android:startColor="#FFFFFF" /> <stroke android:width="4dp" android:color="#238da0" /> </shape> |
drawable/btn_round_edge.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:tint="#238da0"> <gradient android:angle="90" android:endColor="#FFFFFF" android:startColor="#FFFFFF" /> <stroke android:width="4dp" android:color="#238da0" /> <corners android:radius="10dp" /> </shape> |
drawable/btn_oval.xml
1 2 3 4 5 6 7 |
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <gradient android:endColor="#111" android:startColor="#111" /> </shape> |
drawable/btn_oval_gradient.xml
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <gradient android:angle="90" android:centerColor="#7a5d28" android:endColor="#ad853a" android:startColor="#ffc456" /> </shape> |