android自定义button样式

1,在drawable文件夹下定义button_default.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="rectangle" >
            <solid android:color="#FFEC7600" />

            <corners
                android:bottomLeftRadius="5dip"
                android:bottomRightRadius="5dip"
                android:topLeftRadius="5dip"
                android:topRightRadius="5dip" />
        </shape>
    </item>
    <item
        android:bottom="1px"
        android:left="1px"
        android:right="1px"
        android:top="1px">
        <shape>
            <gradient
                android:angle="90"
                android:centerX="0.5"
                android:centerY="0.5"
                android:endColor="#FFFED69E"
                android:startColor="#FFEC7600"
                android:type="linear" />

            <corners
                android:bottomLeftRadius="5dip"
                android:bottomRightRadius="5dip"
                android:topLeftRadius="5dip"
                android:topRightRadius="5dip" />
        </shape>
    </item>

</layer-list>

 2,定义button_pressed.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="rectangle" >
            <solid android:color="#FFEC7600" />

            <corners
                android:bottomLeftRadius="5dip"
                android:bottomRightRadius="5dip"
                android:topLeftRadius="5dip"
                android:topRightRadius="5dip" />
        </shape>
    </item>
    <item
        android:bottom="1px"
        android:left="1px"
        android:right="1px"
        android:top="1px">
        <shape>
            <gradient
                android:angle="90"
                android:centerX="0.5"
                android:centerY="0.5"
                android:endColor="#FFEC7600"
                android:startColor="#FFFED69E"
                android:type="linear" />

            <corners
                android:bottomLeftRadius="5dip"
                android:bottomRightRadius="5dip"
                android:topLeftRadius="5dip"
                android:topRightRadius="5dip" />
        </shape>
    </item>

</layer-list>

  3,定义按钮按下后的效果变化描述文件drawable/button.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/button_pressed" android:state_pressed="true"/>
    <item android:drawable="@drawable/button_default"/>

</selector>

 4,布局中引用:

android:background="@drawable/button"

转载:http://blog.csdn.net/lucherr/article/details/7476941