Remove background drawable programmatically in Android

前端 未结 11 1492
忘掉有多难
忘掉有多难 2020-12-07 17:17

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:

相关标签:
11条回答
  • 2020-12-07 17:52

    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
    
    0 讨论(0)
  • 2020-12-07 17:55

    This helped me remove background color, hope it helps someone. setBackgroundColor(Color.TRANSPARENT)

    0 讨论(0)
  • 2020-12-07 17:59

    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.

    0 讨论(0)
  • 2020-12-07 18:00

    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);
    
    0 讨论(0)
  • 2020-12-07 18:01

    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); 
    
    0 讨论(0)
提交回复
热议问题