In a recent article we looked at how to apply themes to Android apps. In order to further explore how themes work, it is necessary to try to understand precisely how styles and themes are applied to controls. To this end, we will look at building a simple custom control, and then learn how to apply styles and themes to it.
Archive for May, 2011
In this article we are going to look at a useful mechanism for applying styles to sections of text. While it is easy enough to style blocks of text using standard Android styles, there is also a mechanism for applying styles to text at a sub-block level. In HTML it is possible to add emphasis by applying inline markup as shown in this sentence. In Android we can apply a style to a TextView widget which will apply a given style to a specific block of text, but what if we want finer grained control like that of HTML? We use Spans: a mechanism for applying different styles to a block of text to character level.
If you have read the other articles in this series, then you should be getting quite familiar with applying styles to layouts and widgets, and we can get some pretty good results by combining the techniques that we’ve learned so far. While it is certainly possible to apply a, for example, button style to every occurrence of a button widget within our app, there is actually an easier way: Themes. Themes are strangely under-documented on the Android Developer website, but they are an extremely useful tool for applying a UI design consistently across an app, and even applying a consistent UI design across multiple apps.
In the previous articles we have looked at a couple of animation types and the stock interpolators that are available to us. Next we’ll look at the remaining animation types.
You can get the source code for the project that we’re working on here.
We’ve already encountered translate and alpha animations, and there are a couple more: rotate and scale. These are fairly self-explanatory as they allow us to rotate and scale a view respectively. There is a final animation type, known as an Animation Set which allows us to combine animations together. Animation sets are extremely powerful, and allow us to do some quite complex things.