如何删除(常规)视图的背景(Android)

Tal*_* A. 8 java android background view

我有以下代码:

View view = new View(this);  
view.setBackgroundDrawable(...);  
...  
Run Code Online (Sandbox Code Playgroud)

在这里,我想删除该背景.
就像以前一样把它转回来.

我试过这些但失败了:

view.setBackgroundDrawable(null);  
view.setBackgroundColor(0xFF000000);  
view.setBackgroundColor(0x00000000);  
Run Code Online (Sandbox Code Playgroud)

还有什么想法吗?

tac*_*one 21

view.setBackgroundDrawable(null); 应该管用.

您可以尝试以下方法之一:

v.setBackgroundColor(Color.WHITE);
//or
v.setBackgroundColor(Color.parseColor("#ff0000")); //whatever color
Run Code Online (Sandbox Code Playgroud)

确保您应用背景的视图是正确的实例.

  • 非常小的更新:`setBackgroundDrawable(Drawable d)` 现在已弃用。改用`setBackground(Drawable d)`。 (3认同)