一个按钮被按下,应该有一个被按下的效果,以反馈给用户。但是android如何实现呢?
1、android本身默认有按下的效果,在android4.0以上,按下按钮是一般是蓝色
2、自定义:通过两张图片来实现:当按钮没有按下时是图片A,被按下时是图片B,
也就是通过XML文件来实现两张图片的选择性显示
自定义方法的实现:
XML调用是直接调用@drawble/play_button
代码调用是调用R.drawble.play_button
在drawble文件里要有以下文件
1、@drawable/state_pressed_bigbutton(被按下时显示的图片)
2、@drawable/imagebutton_play_button(没有被按下时显示的图片)
3、play_button.xml
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/state_pressed_bigbutton">
</item>
<item
android:state_pressed="false"
android:drawable="@drawable/imagebutton_play_button">
</item>
</selector>