Resolving Android theme colours programmatically

The Android styling and theming system can be an enigmatic beast at the best of times. In some of the SDKs at Zendesk, we need to resolve theme attribute colours at runtime, and today I learned that there’s a big difference depending on whether you specify a colour as a reference or as a literal value.

Linkifying a TextView after setting text

Just a quick one.  You probably already know that you can automatically convert URLs in a TextView into clickable links like this: mTextView.setAutoLinkMask(Linkify.WEB_URLS); I recently learned that this will only work where you can call setAutoLinkMask() before setting text in the TextView.  The simple solution is to set the text after calling setAutoLinkMask(), but if […]

Roboguice – use it, it’s really easy.

Roboguice is an awesome thing. If, like me, you put off looking into it for fear it might be time consuming then don’t fear: it is really, really easy.  Using it simply you can forget about loads of boilerplate code like findViewById, Context.getSystemService and so on. The project’s getting started page tells you all you […]

Android snippet: refer to a colour in code / programmatically

Here’s another possible Android gotcha.  Say you have a colour like this defined in an xml file: <color name=”red”>#FF0000</color> 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 […]