Android Tutorial

(avery) #1

By : Ketan Bhimani


214 

optional fields. Styles are typically defined within the resource file
res/values/styles.xml. The XML file consists of a resources tag with
any number of style tags, which contain an item tag for each
attribute and its value that is applied with the style.

The following is an example with two different styles:

<?xml version=”1.0” encoding=”utf-8”?>






When applied, this style sets the padding to two pixels and the
textSize to eight pixels. The following is an example of how it is
applied to a TextView from within a layout resource file:

<TextView
style=”@style/padded_small”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Small Padded” />


Styles support inheritance; therefore, styles can also reference
another style as a parent. This way, they pick up the attributes of
the parent style. The following is an example of how you might use
this: