Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear Image in the Imageview

I went through many threads but i could not get the answer yet .

I am setting an image to the imageView programmatically as

imageview.setBackgroundResource(R.Drawable.image);

if i set image as the above , will the image get cleared if i give

imageview.setImageDrawable(null);

what does imageview.setBackgroundDrawable(null) meant ?

What is the difference between

imageview.setImageDrawable(null);

and

imageview.setImageBitmap(null);

and

imageview.setBackgroundDrawable(null);
like image 708
VIGNESH Avatar asked Dec 05 '22 09:12

VIGNESH


2 Answers

setBackgroundDrawable() is deprecated. You should use setBackground instead.

Basically the difference is the parameter. In setImageBitmap() you have to pass a Bitmap object. In setImageDrawable() you have to pass a Drawable object. setBackground just change the background of the imageview.

The imageview can have a background and a image content. If you are defining the background and want to clear the imageview, you should use setBackground(null).

like image 71
Renan Bandeira Avatar answered Dec 06 '22 23:12

Renan Bandeira


Did you tried with :

imageview.setImageResource(android.R.color.transparent);
like image 22
Hardik Joshi Avatar answered Dec 06 '22 22:12

Hardik Joshi