How can I set the background color of an Activity to white programatically?
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));
When I do this, Eclipse flags it with "Should pass resolved color instead of resource id here: getResources().getColor(android.R.color.red)".
Change last line to
root.setBackgroundColor(getResources().getColor(android.R.color.red));
This answer works; but it is still not completely programmatic as per the questioner. I would suggest Arunkumar's answer below.
I don't think this asnwer is correct. This is NOT setting the color to the activity, this will cause overdraw. The right answers is down below and should be like
window.decorView.setBackgroundColor(getResolvedColor(R.color.your_color))