moritzgloeckl moritzgloeckl - 4 years ago 123
Android Question

Android: Changing Background-Color of the Activity (Main View)

I want to change the background color of my Main-View (not a Button or a Text-View) just the real background which is normally black... I got this code:

view.setBackgroundColor(0xfff00000);


This is inside an OnClickListener, but it just changes the background of the Button... Please help me, thanks a lot!

Answer Source

Try creating a method in your Activity something like...

public void setActivityBackgroundColor(int color) {
    View view = this.getWindow().getDecorView();
    view.setBackgroundColor(color);
}

Then call it from your OnClickListener passing in whatever colour you want.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download