Reputation: 2632
I'm trying to set the background of a very simple layout:
LinearLayout ll = (LinearLayout) findViewById(R.id.simple_layout);
This works:
ll.setBackgroundColor(Color.WHITE);
But this doesn't:
ll.setBackgroundColor(R.color.white);
And yes, I verified that R.color.white
is defined in a colors.xml file under /res/values
.
What am I missing?
Upvotes: 3
Views: 4232
Reputation: 28359
As @Ali points out when you have it set in XML it becomes a resource. This is very confusing obviously because you don't think of it as a resource, you think of it as a value. But just like all the other resources, it is a resource. So yes, you have to use setBackgroundResource()
Upvotes: 1