Styles inline, create theme example code






Using Themes

One problem with styles is that you need to add an attribute specification of style=”@style/…” to every view definition that you want it to apply to. If you have some style elements you want applied across an entire activity, or across the whole application, you should use a theme instead. A theme is really just a style applied broadly; but in terms of defining a theme, it’s exactly like a style. In fact, themes and styles are fairly interchangeable: you can extend a theme into a style or refer to a style as a theme. Typically, only the names give a hint as to whether a style is intended to be used as a style or a theme.
To specify a theme for an activity or an application, add an attribute to the <activity> or <application> tag in the AndroidManifest.xml file for your project. The code might look like this:

You can find the Android-provided themes in the same folder as the Android-provided styles, with the themes in a file called themes.xml. When you look inside the themes file, you will see a large set of styles defined, with names that start with Theme. You will also notice that within the Android-provided themes and styles, there is a lot of extending going on, which is why you end up with styles called Theme.Dialog.AppError, for example.

The Android guide to styles and themes:

Apress Pro Android 5

Android 6 – Styles and Themes

Category: AndroidPrograming

Join the discussion

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