如何通过编程将活动的背景颜色设置为白色?
发布于 2011-01-22 01:25:31
获取所用根布局的句柄,然后在其上设置背景色。根布局是您用来调用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));
发布于 2012-12-14 03:08:29
在setContentView()
调用之后,在您的活动中添加这一行
getWindow().getDecorView().setBackgroundColor(Color.WHITE);
发布于 2012-09-04 16:42:21
我更喜欢按主题着色。
<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>
https://stackoverflow.com/questions/4761686
复制相似问题