Styles and Themes

A style is one or more attributes applied to a single element (for example, 10 point red Arial font, applied to a TextView). A style is applied as an attribute to an element in a layout XML file.

A theme is one or more attributes applied to a whole screen — for example, you might apply the stock Android Theme.dialog theme to an activity designed to be a floating dialog box. A theme is assigned as an attribute to an Activity in the manifest file.

Both styles and themes are defined in a <style> block containing one or more string or numerical values (typically color values), or references to other resources (drawables and so on). These elements support inheritance, so you could have MyBaseTheme, MyBaseTheme.Fancy, MyBaseTheme.Small, and so on.

For a complete discussion on styles and themes, read Applying Styles and Themes.

Source file format: XML file requiring a <?xml version="1.0" encoding="utf-8"?> declaration, and a root <resources> element containing one or more <style> tags.

Resource source file location: res/values/styles.xml (File name is arbitrary, but standard practice is to put all styles into a file named styles.xml.)

Compiled resource datatype: Resource pointer to a Java CharSequence. Resource reference name:

<style name=string [parent=string] >

<item name=string>Hex value | string value

reference</item>+

</style>

Holds one or more <item> elements, each describing one value. This style, which is a bundle of values, can be referred to as a theme.

• name - The name used in referring to this theme.

• parent - An optional parent theme. All values from the specified theme will be inherited into this theme. Any values with identical names that you specify will override inherited values. The name must be qualified by the package, but you don't need the /style directive (for example, android:Theme for the base Android theme, or MyTheme for a theme defined in your package).

A value to use in this theme. It can be a standard string, a hex color value, or a reference to any other resource type. For examples of how to declare and apply styles and themes, read Applying Styles and Themes.

0 0

Post a comment