如何更改按下和释放时 ImageButton 的图像?
我希望在我的 android 应用程序中,ImageButton
在按下和释放时更改其图像,并且当再次按下释放时,ImageButton
的图像将更改回来,怎么做呢?
I want that in my android application, the ImageButton
change its image when it is pressed and released, and when it is pressed released again, the image for ImageButton
will be changed back , how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建一个选择器(它是一个 xml 文件)放入可绘制文件夹中。在 xml 中,该 xml 的五个路径代替了实际图像
android:background="@drawable/imageselector"
或在程序中,您也可以使用imageview.setBackgroundDrawable(R.drawable. imageselector)
以下是我的选择器
imageselector.xml
create a selector (it is an xml file) put in drawable folder. and in xml five path of that xml instaed of actual image
android:background="@drawable/imageselector"
or in program also you can get the same usingimageview.setBackgroundDrawable(R.drawable.imageselector)
Following is my selector
imageselector.xml
为此使用选择器...这是一个链接..
http://developer.android.com/reference/android/widget/ImageButton.html
use selector for this...here is a link for this..
http://developer.android.com/reference/android/widget/ImageButton.html
您可以使用图像视图进行相同的操作:
代码隐藏:
You can use Image View for the same:
Code behind: