1.编写一个按键up的shape和一个按键down时的shape。(区别在于实体部分颜色不同)
1)Up的shape
<?xml version="1.0"encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00000000"/><!--实体透明-->
<padding
android:bottom="10dp"
android:top="10dp"
android:left="10dp"
android:right="10dp"/>
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
<stroke
android:width="@dimen/button_width"
android:color="@color/button_font_blue"/>
</shape>
2)down时的shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#5dcfe8" />
<padding
android:bottom="10dp"
android:top="10dp"
android:left="10dp"
android:right="10dp"/>
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
<stroke
android:width="@dimen/button_width"
android:color="@color/button_font_blue" />
</shape>
2.编写selector,transparent_button
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--enable一定要写在前面-->
<item android:state_enabled="false" android:drawable="@drawable/transparent_button_down"/>
<item android:state_pressed="false" android:drawable="@drawable/transparent_button_up"/>
<item android:state_pressed="true" android:drawable="@drawable/transparent_button_down"/>
</selector>
3.在布局里面添加button,background引用transparent_button
<Button
android:id="@+id/btRight"
android:layout_width="@dimen/udp_button_height"
android:layout_height="@dimen/udp_button_height"
android:layout_alignBottom="@+id/btOk"
android:layout_marginLeft="@dimen/udp_button_spacing"
android:layout_toRightOf="@+id/btOk"
android:textColor="@color/button_font_blue"
android:text="→"
android:background="@drawable/transparent_button"/>
效果图:
工程文件下载地址:
http://download.csdn.net/detail/cx415462822/9657297