问题
如何以编程方式将活动的背景颜色设置为白色?
#1 热门回答(210 赞)
在setContentView()
call之后,在你的活动中添加此单行
getWindow().getDecorView().setBackgroundColor(Color.WHITE);
#2 热门回答(122 赞)
获取所使用的根布局的句柄,然后在其上设置背景颜色。根布局是你调用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));
#3 热门回答(66 赞)
我更喜欢按主题着色
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">@color/custom_theme_color</item>
<item name="android:colorBackground">@color/custom_theme_color</item>
</style>