I want to remove the background drawable @drawable/bg
programmatically.
Is there a way to do that?
Currently, I have the following XML in my layout:
First, you have to write in XML layout:
android:visibility="invisible" <!--or set VISIBLE-->
then use this to show it using Java:
myimage.setVisibility(SHOW); //HIDE
This helped me remove background color, hope it helps someone.
setBackgroundColor(Color.TRANSPARENT)
Use setBackgroundColor(Color.TRANSPARENT)
to set the background as transparent, or use setBackgroundColor(0)
. Here Color.TRANSPARENT
is the default attribute from color class. It will work fine.
I have a case scenario and I tried all the answers from above, but always new image was created on top of the old one. The solution that worked for me is:
imageView.setImageResource(R.drawable.image);
Try this code:
imgView.setImageResource(android.R.color.transparent);
also this one works:
imgView.setImageResource(0);
but be careful this one doesn't work:
imgView.setImageResource(null);