Tuesday, 11 November 2014

Android Layout Background Dynamically

how to set "Layout" background dynamically in android ?
               
                here is the best practice to set the background for a layout in android. Copy the below code 
and paste it in onCreate().



                               RelativeLayout rl = (RelativeLayout) findViewById(R.id.Rlayout);
                               rl.setBackgroundColor(Color.parseColor("#101000"));



Use the below link to get more colour Hex codes


If you want to set an image to layout background then use the below code. Before using this code first you need to copy the image to drawable folder that is in res (Resources) folder.


                               RelativeLayout ll = (RelativeLayout) findViewById(R.id.Rlayout);
                               ll.setBackgroundResource(R.drawable.background);

No comments:

Post a Comment