Android Theme controlled styleable UI elements

     Beauty of Android's UI design is a very good separation of concerns for application developers and the user interface folks. In my experience, the user interface folks don't prefer looking into the code and figure out as to how an UI element's style is implemented and in some cases they don't even want to look at the layout resources. All they have is a document describing the look and feel of the application and their desire to work only with styles and theme files. Fortunately, Android supports this by providing reference attributes. These reference attributes can refer to styles, drawable resources, color etc.

attrs.xml
   

styles.xml



layout.xml

   Application developers can use the desired styles via reference attribute, instead of directly specifying the view attributes. The only catch is that the attribute should point to a valid style in the current theme.



themes.xml

   User interface folks can just use the styles and themes to change the look and feel of various UI elements, without having to deal with complicated layouts, hierarchy viewer etc. The only catch is that the naming styles of attributes should be friendly enough, which is always a challenge in a complicated application with similar looking UI elements.




AndroidManifest.xml

  Desired theme can be applied either to a specific Activity or the entire application.


No comments: