我重用ImageViews为我的显示,但在某些时候,我没有值把它。

那么如何在Android中清除ImageView呢?

我试过了:

mPhotoView.invalidate();
mPhotoView.setImageBitmap(null);

他们都没有清除视图,它仍然显示以前的图像。


当前回答

这对我很有用。

emoji.setBackground(null);

这会在运行时崩溃。

viewToUse.setImageResource(android.R.color.transparent);  

其他回答

要删除ImageView中的图像,请使用: title_image.setImageResource (1); 这对我很有用

editText.setText (" ");

imageView.setImageResource(0);

我知道这很旧了,但我能用

viewToUse.setImageResource(0);

看起来不应该有用,但我一时兴起试了一下,效果很好。

我可以通过定义一个可绘制对象(类似于blank_white_shape.xml)来实现这一点:

<shape xmlns:android="http://schemas.android.com/apk/res/android"       
       android:shape="rectangle">
    <solid android:color="@android:color/white"/>
</shape>

当我想清除图像视图时,我只需调用

 imageView.setImage(R.drawable.blank_white_shape);

这对我来说非常有用!

我也遇到了同样的问题,我把视图的背景色改为布局背景色,你可以这样做:

 edit_countflag.setBackgroundColor(Color.parseColor("#ffffff"));

//然后设置图像

edit_countflag.setImageResource(R.drawable.flag_id);