Here’s another possible Android gotcha. Say you have a colour like this defined in an xml file:
Then in some code you do something like:
TextView textView = new TextView(context); textView.setTextColor(R.color.red);
You’ll find that the text comes out like some darkish grey colour and this is because it used the resource id (which is a large int) and not the colour value. To get this to work as expected you need to make a small change
TextView textView = new TextView(context); textView.setTextColor(context.getResources().getColor(R.color.red));
Naturally, you need to get the resources from a context, as shown above.