removing backgroundcolor of a view in android removing backgroundcolor of a view in android android android

removing backgroundcolor of a view in android


You should try setting the background color to transparent:

view.setBackgroundColor(0x00000000);


You can use

View.setBackgroundColor(Color.TRANSPARENT);

or

View.setBackgroundColor(0);

Please remember that almost everything visible on the screen extends View, like a Button, TextView, ImageView, any kind of Layout, etc...


All of the answers about setting color to transparent will work technically. But there are two problems with these approaches:

  1. You'll end up with overdraw.
  2. There is a better way:

If you look at how View.setBackgroundColor(int color) works you'll see a pretty easy solution:

/** * Sets the background color for this view. * @param color the color of the background */@RemotableViewMethodpublic void setBackgroundColor(@ColorInt int color) {    if (mBackground instanceof ColorDrawable) {        ((ColorDrawable) mBackground.mutate()).setColor(color);        computeOpaqueFlags();        mBackgroundResource = 0;    } else {        setBackground(new ColorDrawable(color));    }}

The color int is just converted to a ColorDrawable and then passed to setBackground(Drawable drawable). So the solution to remove background color is to just null out the background with:

myView.setBackground(null);