Themes

This section discusses how themes work as resources. See also chapter Theming and styling, it has in-depth discussions of styles and theming in LWUIT.

A theme can be defined using a key value properties file containing selectors and values. A selector can be defined as an attribute value, optionally with a component name prepended to it for narrowing the selection further.

The value of an entry in the theme depends on the type of the entry, some entries such as bgImage expect an image object and some entries such as Font expect a font definition. Most entries just expect numbers. For example, this is a typical snippet from a theme:

sel#fgColor=0017ff
font=systemSmall
Form.bgImage=myBackground
Form.font=Serif
SoftButton.bgColor=ff
SoftButton.fgColor=ffffff

To add this theme into a resource, add the following:

<build dest="src/myresourceFile.res">
    <font logicalName="Serif" bold="true" />
    <font createBitmap="false" name="systemSmall" system="FACE_SYSTEM ; STYLE_PLAIN; SIZE_SMALL" />
    <image file="images/background.png" name="myBackground" />
    <theme file="themes/myTheme.conf" name="myTheme" />
</build>

This theme can then be installed as follows:

UIManager.getInstance().setThemeProps(res.getTheme(myTheme));