tags:

views:

108

answers:

2

How to dynamically change the background LinearLayout?

A: 

Did you try one of these :

yourLayout.setBackgroundColor(int color);
yourLayout.setBackgroundDrawable(Drawable d);
yourLayout.setBackgroundResource(int resid);

and if does not refresh on its own, this should give it a boost :

   yourLayout.invalidate();
Sephy
Tried not once, not working
A: 

I'm at work right now, so I can't test this, but I believe this should work:

LinearLayout linLay = (LinearLayout) findViewById(R.id.theLinearLayoutId);

//set background to a color
linLay.setBackgroundColor("#404040");

//set background to a drawable
linLay.setBackgroundDrawable(drawableItem);

//set background to a resource
linLay.setBackgroundResource(R.id.backgroundResource);

I'll try to test this when I get home.

Edit: beaten by Sephy :P

kcoppock
Not working :(.
Bizon, from your comment, are you just trying to change to a different layout when the phone is switched to landscape mode versus portrait mode?If so, you should make a new layout.xml file, and place it under res/layout-land/http://developer.android.com/guide/topics/resources/index.html
kcoppock