I'm trying to set the background color for a tablerow in android and am having trouble referencing the proper int. Below is the code. Am I doing something wrong? The color that turns up in the background is a light grey.
<?xml v开发者_如何学Cersion="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Trackfolio</string>
<color name="colorWhite">#FFFFFF</color>
<color name="colorBlack">#000000</color>
<color name="colorLightBlue">#6495ED</color>
</resources>
row.setBackgroundColor(R.color.colorLightBlue);
Also is there a way to set the text color?
tv.setTextColor(R.color.colorBlack);
cfarm54,
The way you are accessing the colors you are getting the offset location in R.java gen file.
You need to access them like this...
Resources res = context.getResources();
row.setBackgroundColor(res.getColor(R.color.high_priority));
Oops: dumb me, you should use tableRow.setBackgroundResource() when referecing a color resource.
Try setBackgroundResource(int color)
. Using setBackgroundColor
uses the int that R.color.colorLightBlue uses to reference your defined color, and tries to parse it as a color, rather than retrieving the referenced color.
精彩评论