如何为按钮点击事件添加类似于下图的点击效果?
我的 Activity 中的按钮已经将其背景设置为图像,因此我不确定如何像本教程一样添加状态背景:
Android Button color changing on onClick?
最佳答案
您需要两张图片,一张用于正常状态,另一张用于按下状态。首先创建一个选择器
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/pressed_image" android:state_pressed="true"/>
<item android:drawable="@drawable/normal_image"/>
</selector>
在您的按钮中添加此选择器作为背景。
关于android - 如何在点击事件中为按钮添加点击效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19984497/