How to dynamically change the background LinearLayout?
3
-
In what way? What are you looking to change?Aaron C– Aaron C2010-08-18 13:54:40 +00:00Commented Aug 18, 2010 at 13:54
-
If you change the position of the phone to change its screen horizontally or vertically.user413881– user4138812010-08-18 14:16:39 +00:00Commented Aug 18, 2010 at 14:16
-
You should have specified your situation in your post bizon, that would have helped us to answer you. look at the comment from kcoppock, it should help you.Sephy– Sephy2010-08-18 22:33:58 +00:00Commented Aug 18, 2010 at 22:33
Add a comment
|
2 Answers
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);
4 Comments
Kevin Coppock
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/ developer.android.com/guide/topics/resources/index.html
Confuse
setBackgroundColor(...) is a integer method. You cannot pass a string a string argument to it.
Alk
setBackgroundColor(Color.parseColor("")); would work, just put the color string inside the parseColor method
LiuWenbin_NO.
@user413881, I hit the "Up Arrow" just now because I tried and it neither worked for me but, I looked my code again, and found that works, the issue was I have a customized ChipLayout (extends LinearLayout), and I only changed the background resource on the reference of the ChipLayout, but forgot to change the background resource of the ChipLayout itself, change to operate on the ChipLayout everything works. Hope this could be helpful to other.