android自定义加减按钮自定义加减按钮
本文实例为大家分享了android自定义加减按钮的具体代码,供大家参考,具体内容如下
1、定义两个shape:
my_button_shape_normal.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#007FFF" />
<corners android:radius="5dip" />
<padding
android:bottom="1dp"
android:left="10dp"
android:right="10dp"
android:top="1dp" />
</shape>
my_button_shape_pressed.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#007FFF" />
<corners android:radius="5dip" />
<padding
android:bottom="1dp"
android:left="10dp"
android:right="10dp"
android:top="1dp" />
</shape>
2、定义一个drawable:my_button_style.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/my_button_shape_normal" android:state_focused="false"
android:state_pressed="false"></item>
<item android:drawable="@drawable/my_button_shape_pressed" android:state_focused="false"
android:state_pressed="true"></item>
</selector>
3、定义button布局(mybutton.xml):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/reduce"
android:layout_width="50dp"