Themes and styles

Extracting style information from your layout files
This is generally a good practice. It allows you to keep layout separate from style which in turn is kept separate from the program logic. Web development has gone this way with HTML, CSS and back end technologies like servlets. Android supports this separation too. The layout information is kept in the layout xml files. Style information can also be kept there, but for a large application this will get cumbersome. For example if you decide to change the font used on your buttons you will have a big search and replace on your hands. If you use separate styles it will just need to be changed in one place. The holy grail of programming. Finally the program logic is kept in the class files (Activities and the like). All nice and organised.

A further separation that Android promotes is the removal of static strings from the logic. They are placed in the strings.xml file. This seems a bit long winded at first, but once your application starts to grow it it the only way to fly. Just make sure you use names for the strings that make sense in your program. You don't want to have to look up something cryptic to see what the string that it points to is.

The separation of static text out into strings.xml also facilitates localization.

There is a nice tutorial on themes and style here.

Comments

Popular posts from this blog

Building a choropleth map for Irish agricultural data

Early Stopping with Keras

AutoCompleteTextView backed with data from SQLite in Android