如何设置活动的背景颜色为白色编程?如何设置、白色、颜色、背景

2023-09-11 20:18:03 作者:晚风

我如何设置一个活动的背景色为白色编程?

How can I set the background color of an Activity to white programatically?

推荐答案

获取一个句柄使用的根布局,然后设置背景色。根布局是不管你用所谓的setContentView。

Get a handle to the root layout used, then set the background color on that. The root layout is whatever you called setContentView with.

 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));