如何以编程方式将活动的背景色设置为白色?
2022-08-31 08:00:49
如何以编程方式将活动的背景色设置为白色?
通话后,在活动中添加这一行setContentView()
getWindow().getDecorView().setBackgroundColor(Color.WHITE);
获取所用根布局的句柄,然后设置其背景色。根布局是您称之为 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));