Applying a Theme

A theme is a collection of styles that override the look and feel of Android widgets. Themes were inspired by Cascading Style Sheets (CSS) used for web pages—they separate the content of a screen and its presentation or style. Android is packaged with several themes that you can reference by name,4 or you can make up your own theme by subclassing existing ones and overriding their default values.

We could define our own custom theme in res/values/styles.xml, but for this example we'll just take advantage of a predefined one. To use it, open the AndroidManifest.xml editor again, and change the definition of the About activity so it has a theme property.

4. See http://d.android.com/reference/android/R.style.html for symbols beginning with "Theme_."

1:50 AM

About Android Sudoku

Sudoku Is a logic-based number placement puzzle. Starting with a partially completed 9x9 grid, the objective Is to fill the grid so that each row, each column, and each of the 3xB boxes (also called blocks contains the digits 1 to 9 exactly once.

Figure 3.8: First version of the About screen

Download Sudokuvl/AndroidManifest.xml

<activity android:name=".About"

android:label = "@string/about_title" android:theme= "'@android:style/Theme.Dialog"> </activity>

The @android: prefix in front of the style name means this is a reference to a resource defined by Android, not one that is defined in your program.

Running the program again, the About box now looks like Figure 3.9, on the following page.

Many programs need menus and options, so the next two sections will show you how to define them.

Figure 3.9: About screen after applying the dialog box theme

0 0

Post a comment