1、使用Draw 9-patch工具制作图片
2、布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5px"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:background="@drawable/green1"
android:layout_margin="5px"
android:layout_width="match_parent"
android:layout_height="50px"
android:text="我是普通图片背景"
/>
<Button
android:id="@+id/button2"
android:background="@drawable/green"
android:layout_margin="5px"
android:layout_width="450px"
android:layout_height="150px"
android:text="我是9-Patch图片背景(按钮宽度和高度固定)"
/>
<Button
android:id="@+id/button3"
android:background="@drawable/button_state"
android:layout_margin="5px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="我是9-Patch图片背景(单击会变色)"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/red" android:state_pressed="true"/>
<item android:drawable="@drawable/green" android:state_pressed="false"/>
</selector>