Clear Image in the Imageview
Solution 1
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)
.
Solution 2
Did you tried with :
imageview.setImageResource(android.R.color.transparent);
Solution 3
There are many ways to inflate & clear ImageView
If you have inflated using,
imageView.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.xyz));
then clear using,
imageView.setImageDrawable(null);
If you have inflated using,
imageView.setBackgroundResource(R.drawable.xyz);
then clear using,
imageView.setBackground(null);
So basically if you inflate ImageDrawable, then you remove ImageDrawable. If you inflate backgroung, then you remove background. Similarly for ImageBitmap.
Solution 4
I had same problem. Here,
imageview.setImageDrawable(null);
will clear the the background of an ImageView
,
imageview.setImageBitmap(null);
will clear the ImageBitmap from an ImageView
, and
imageview.setBackgroundResource(R.Drawable.image);
will set the Images for your path e.g your path (R.Drawable.image
)
VIGNESH
Updated on August 19, 2020Comments
-
VIGNESH over 3 years
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);