Reputation: 225
How to dynamically change the background LinearLayout?
Upvotes: 8
Views: 21529
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
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