首先在res/drawable下自行定义一个xml,分别设定按钮获得焦点、按钮按下、常规状态下的按钮表现样式
[b]drawable/mButton.xml[/b]
然后在main.xml中将mButton赋值给Button组件中的background属性
[b]layout/main.xml[/b]
[b]drawable/mButton.xml[/b]
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/btfocused"
/>
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/btnfocusedpressed"
/>
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/btndefault"
/>
</selector>
然后在main.xml中将mButton赋值给Button组件中的background属性
[b]layout/main.xml[/b]
<Button
android:id="@+id/mButton1"
android:background="@drawable/mButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="MyButton"
/>