Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 usually black... I got this code:

view.setBackgroundColor(0xfff00000); 

This is inside an OnClickListener, but it just changes the background of the Button.

like image 1000
moritzg Avatar asked Jan 22 '12 12:01

moritzg


People also ask

How can I change the color of my activity bar in android?

Just go to res/values/styles.edit the xml file to change the color of action bar.

How do you change the background color to white?

Right click, and go to personalize - click background - solid color - and pick white. You should be in good shape!

Which of the following is used to set the background color in android?

android:background="" is the attribute used to set background for any Layout file. You can directly specify the value as HEX color code as we do for CSS files in HTML.


1 Answers

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.

like image 50
Squonk Avatar answered Sep 20 '22 18:09

Squonk