How to remove background (normal) view (Android)

I have the following code:

View view = new View(this); view.setBackgroundDrawable(...); ... 

And here I want to remove this background.
Just return it as it was before.

I tried these and failed:

 view.setBackgroundDrawable(null); view.setBackgroundColor(0xFF000000); view.setBackgroundColor(0x00000000); 

Any ideas?

+7
source share
2 answers

view.setBackgroundDrawable(null); must work.

You can try one of them:

 v.setBackgroundColor(Color.WHITE); //or v.setBackgroundColor(Color.parseColor("#ff0000")); //whatever color 

Make sure the view you are applying the background to is the correct instance.

+17
source

This is because view.setBackgroundColor(int) expects the color resource to not be an "actual" integer value. Try declaring it in your .xml color, see this . However, I'm not quite sure what you mean by deleting the background. If you want it to have the original value, I suggest you save the source file with the ability to draw (using getBackground() ). Otherwise, you are likely to lose formatting, since most of the default backgrounds in Android are Drawable (selector), not plain colors.

+1
source

All Articles