Android Change Background Color

Android Change Background Color

You want to change the background color of Android layout. It can be set at design time or runtime. Let’s see we can change the color of layout dynamically.

 
View v = (View) findViewById(R.id.layout);
v.setBackgroundColor(color.background_light);
        

Complete code.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    
    View v = (View) findViewById(R.id.layout);
    v.setBackgroundColor(color.background_light);
}

Above program loads the screen with default color white. You can write the code on button click to change the color.

Tags:

Android Change Background ColorAndroid screen navigation example using Activity and IntentAndroid WebView ExampleAndroid EditText TutorialAndroid Button onClickListener ExampleAndroid Button ClickJQuery how to change background imageAndroid Tutorial For BeginnersBest Android ApplicationsHow to change your IPHow to change facebook name

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.