在其他人的博客里看到其实实现按钮点击效果的方法有很多,这里提到的只是其中一个办法
图片素材(我自己用截图截的,可以自己搞)
放到mipmap目录下(studio是在这个目录下 , eclipse 直接放在drawable下)
在drawable目录下创建一个btn_select.xml 文件
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false" android:drawable="@mipmap/black"/> <item android:state_pressed="true" android:drawable="@mipmap/blue"/> </selector>
在布局的时候用background调用该文件就行了
调用方法:
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton" android:background="@drawable/btn_selector" android:layout_above="@+id/button2" android:layout_centerHorizontal="true" android:layout_marginBottom="113dp" />