New buttons

A quick and simple way to create a new button style is to add into the layout
android:background=”@drawable/custom_button”
and have that custom_button.xml file in the drawable folder. An example follows.

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" >
        <shape>
            <gradient
                android:startColor="@color/sf_brown_light"
                android:endColor="@color/sf_brown_lighter"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="@color/sf_brown" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item android:state_focused="true" >
        <shape>
            <gradient
                android:endColor="@color/sf_green_light"
                android:startColor="@color/sf_green_lighter"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="@color/sf_brown" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
     <item>        
        <shape>
            <gradient
                android:endColor="@color/sf_green_mid"
                android:startColor="@color/sf_green_light"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="@color/sf_brown" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>
This entry was posted in Android. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *