1.加入属性
android:background="@drawable/btn_selector"
2.drawable 下创建btn_selector.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/shape_bt_login_pressed" android:state_pressed="true"/> <item android:drawable="@drawable/shape_bt_login_normal" android:state_pressed="false"/> </selector>
3.drawable 下创建shap_bt_login_normal.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="8dp"/> <solid android:color="#4169E1"/> </shape>
4.drawable 下创建shap_bt_login_pressed.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="3dp"/> <solid android:color="#DB4537"/> </shape>