user413881
user413881

Reputation: 225

Dynamically change the background LinearLayout

How to dynamically change the background LinearLayout?

Upvotes: 8

Views: 21529

Answers (2)

Kevin Coppock
Kevin Coppock

Reputation: 134664

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(Color.parseColor("#404040"));

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

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

Upvotes: 11

Sephy
Sephy

Reputation: 50392

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();

Upvotes: 15

Related Questions