Sunday, January 11, 2015

How to create a gradient color Button in Android

Button background color drawable gradient
activity_main.xml code snippet

<Button
 android:id ="@+id/push_button"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Button Background Color - Drawable Rectangle Gradient"
 android:background="@drawable/button_bg_rectangle_gradient"
 android:padding="15dp"
 />
res/drawable/button_bg_rectangle_gradient.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <gradient
                android:angle="90"
                android:centerColor="#ff0000"
                android:endColor="#00ff00"
                android:gradientRadius="180"
                android:startColor="#6495ED"
                android:type="radial"
                />
        </shape>
    </item>
</selector>
More android examples