删除ImageButton的图像资源 [英] Remove image resource of ImageButton

查看:78
本文介绍了删除ImageButton的图像资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个透明的ImageButton.单击后,按钮的ImageResource在我的drawable-hdpi文件夹中设置为可绘制对象(基本上,图像显示在透明ImageButton的顶部).我正在使用ImageButton.setImageResource()方法来做到这一点.我的问题是,如何删除图像资源,以便再次只有透明的图像按钮.当然,我需要能够用Java而不是XML做到这一点.我尝试了以下失败的方法:ImageButton.setImageResource(null);我也环顾了一下,找不到答案....在此先感谢您的帮助.

I have a transparent ImageButton. When clicked, the ImageResource of the button is set to a drawable in my drawable-hdpi folder (basically an image is shown on top of the transparent ImageButton). I'm using the ImageButton.setImageResource() method in order to do that. My question is, how can I remove the image resource so that there is only a transparent image button again. Of course, I need to be able to do this in java, not XML. I tried the following which failed to work: ImageButton.setImageResource(null); I also looked around a bit and couldn't find an answer... Thanks in advance for any help.

谢谢大家的回答.佩特·瓦尔加(PéterVarga)的回答正是我所需要的,这就是我要去做的事情.

Thank you all for your answers.. Péter Varga's answer did exactly what I needed so that's what i'm going with.

推荐答案

尝试设置imageButton.setImageResource(android.R.color.transparent).

这篇关于删除ImageButton的图像资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆