How to define style and use it in Android

While developing certain mobile applications such as Game or some kind of data driven application, you always need to follow some design standards like text color, font, size etc. or the image/logo at particular position on each screen and for that you need to define same properties to each
TextView or ImageView widgets on each screen or like so.

And what about if you want to change the logo position from left to right or change the size of text or color. You have to open each layout file and make changes for each TextView or Widget.

But instead of doing this all repeating task we can define all this properties at on place and link to the related widget by defining style. See the example illustrated below.

Create new xml named mystyle.xml(you can choose file name as you want) under res>values directory.
Using style in android

mystyle.xml

Define create style node under resources and assign style name, so we can call style by name by settings widget style. now under style node set properties and its value as item node.

Now give the style reference to your widgets in layout xml.

res>layout>preferences.xml

I hope, the above example is useful to understand you how to use style in android.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *