

Styles and themes are very similar concepts: when we apply a style to an Activity or an application, instead of applying it to a single View, we call it a theme. This is a classic example where using a style would avoid duplication of data, separate the layout structure from its appearance and improve the XML file readability. Moreover, in a consistent and appealing user interface where text messages have all the same size, we will have to replicate the text size information for each TextView in our layout. This is a very bad practice, because if we want to change the text color we should look for each TextView in our user interface definition. Looking at the code above we notice there are some mistakes: we added to the View not only the information regarding its content but also information about how it looks like and we hard-coded it directly. For example let us suppose we have a simple TextView like the one shown below: When using Views we could specify for example the background color, the font color, View size and so on. When we create a layout in XML we use layout managers and Views.

We can imagine that a style is like a CSS in a web page, it separates the content structure from how it is displayed on the screen.

These properties specify the font size, the font family, the background color, font color and so on. A style, on the other hand, specifies a set of properties that have effects on how a View or Window looks like. It helps to create an appealing user interface. What is a theme in Android?Ī theme is a set of styles and can be applied to the whole app or to a single Activity. While the layout and the Views specify the structure of the user interface, styles and themes define their look. This is an important aspect when developing an app because using style and theme we can brand our app and have an harmonious look.

In this article we will describe how we can use style and theme. We also talked about drawable, which is very useful when we want to customize some widget. We saw there are several layout managers and Views provided by the Android SDK and that, if they are not enough, we can create custom layout managers and Views. In the previous articles, we talked about layout and how we can organize our Views so that we can create appealing user interfaces.
