1、在res文件夹下新建一个文件夹drawable
2、在drawable文件夹下面建立一个xml文件:button_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/normal" android:state_pressed="false"/> <item android:drawable="@drawable/pressed" android:state_pressed="true"/> </selector>
3、在value文件夹下的string.xml文件里添加normal【未选中】和pressed【选中】的样式
<drawable name="clr_normal">#ff6501</drawable> <drawable name="clr_pressed">#a44100</drawable>
4、在布局中通过background调用button_selector.xml的样式
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/login_button_selector" />