Warm tip: This article is reproduced from serverfault.com, please click

java-如何通过编程将活动的背景颜色设置为白色?

(java - How to set background color of an Activity to white programmatically?)

发布于 2011-01-21 17:13:17

如何以编程方式将“活动”的背景色设置为白色?

Questioner
SJS
Viewed
0
community wiki 2016-10-25 15:48:27

获取所用根布局的句柄,然后在其上设置背景颜色。根布局就是你使用setContentView调用的内容。

 setContentView(R.layout.main);

  // Now get a handle to any View contained 
  // within the main layout you are using
  View someView = findViewById(R.id.randomViewInMainLayout);

  // Find the root view
  View root = someView.getRootView();

  // Set the color
  root.setBackgroundColor(getResources().getColor(android.R.color.red));