Set background color of TableRow

Martin Hansen picture Martin Hansen · May 20, 2011 · Viewed 21k times · Source

I try to set the background color of a TableRow. Currently I have this in my XML file:

android:background="@color/buttonBackground" 

and i work great. But when it run

row.setBackgroundColor(R.color.red);

the row disappears. Can someone explain why that is?

Answer

Swati picture Swati · May 20, 2011

I believe you need to do:

Resources resource = context.getResources();
row.setBackgroundColor(resource.getColor(R.color.red)