Monday, 28 May 2012

How to set the Background of the Main View of Activity?

You can set the background of the activity main view using the following code

   //get the root view of the activity
 View view = this.getWindow().getDecorView();
   //set the background color to BLUE
 view.setBackgroundColor(Color.BLUE);

getDecorView() retrieve the top-level window decor view (containing the standard window frame/decorations and the client's content inside of that).

if you want to draw a image on the background then use

view.setBackgroundDrawable(getResources().getDrawable(R.drawable.bgimage));

The bgimage need to add in res->drawable-mdpi.

drawable-mdpi stores medium density pixel independence on your phone screen.

No comments:

Post a Comment