Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a background color for linear layout programatically?

How to set a background color for linear layout programatically? I tried following code but not working:

LinearLayout footer = new LinearLayout(activity);
footer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 8));
footer.setBackgroundColor(Color.parseColor("##ffb5d6e1"));
((LinearLayout)v).addView(footer);
like image 719
user1667968 Avatar asked Oct 06 '12 20:10

user1667968


1 Answers

I think your issue is in your line here:

footer.setBackgroundColor(Color.parseColor("##ffb5d6e1"));

Remove the extra '#' symbol so that it is:

footer.setBackgroundColor(Color.parseColor("#b5d6e1"));

I also removed the 'ff' because you were essentially setting the opacity to 100%, which is done by default if you just only use six character long hex values.

like image 168
Andre Perkins Avatar answered Oct 08 '22 19:10

Andre Perkins