Android Tutorial

(avery) #1
Android Tutorial 217

<activity android:name=”.myactivityname”
android:label=”@string/app_name”
android:theme=”@style/myAppIsStyling”>


Unlike applying a style in an XML layout file, multiple themes can
be applied to a screen. This gives you flexibility in defining style
attributes in advance while applying different configurations of the
attributes based on what might be displayed on the screen. This is
demonstrated in the following code:

setTheme(R.style.right);
setTheme(R.style.green_glow);
setContentView(R.layout.style_samples);


In this example, both the right style and the green_glow style are
applied as a theme to the entire screen. You can see the results of
green glow and right-aligned gravity, applied to a variety of
TextView controls on a screen, as shown in
Figure. Finally, we set the layout to the
Activity. You must do this after setting the
themes. That is, you must apply all
themes before calling the method
setContentView() or the inflate() method
so that the themes’ attributes can take
effect.

Packaging styles for glowing text,
padding, and alignment into a theme.

A combination of well-designed and
thought-out themes and styles can make
the look of your application consistent and
Free download pdf