How to clear an ImageView in Android? – Dev

The best answers to the question “How to clear an ImageView in Android?” in the category Dev.


I am reusing ImageViews for my displays, but at some point I don’t have values to put it.

So how to clear an ImageView in Android?

I’ve tried:


None of them have cleared the view, it still shows previous image.


I had a similar problem, where I needed to basically remove ImageViews from the screen completely. Some of the answers here led me in the right direction, but ultimately calling setImageDrawable() worked for me:


(As mentioned in the comment, such usage is documented in the official docs: ImageView#setImageDrawable.)


I used to do it with the dennis.sheppard solution:


it works but it is not documented so it isn’t really clear if it effects something else in the view (you can check the ImageView code if you like, i didn’t).

I think the best solution is:


I like this solution the most cause there isn’t anything tricky in reverting the state and it’s also clear what it is doing.


It sounds like what you want is a default image to set your ImageView to when it’s not displaying a different image. This is how the Contacts application does it:

if (photoId == 0) {
} else {
    // ... here is where they set an actual image ...


I know this is old, but I was able to accomplish this with


Doesn’t seem like it should work, but I tried it on a whim, and it worked perfectly.