Android UI Themes Tutorial

0

This tutorial is meant to get you started and understanding the theme capabilities of  the Android SDK’s API.  Many options such as background color and image on widgets can be changed easily although some such as Activity and Dialog winds must be changed via theme facility.

You can define most of your resources within a styles.xml file located at “ProjectName/res/values/styles.xml”.

An Example of a style.xml file:

<resources>
<!– Base application theme is the default theme. –>
<style name=”Theme” parent=”android:Theme”></style>

<!– Variation on our application theme that has a translucent background. –>
<style name=”Theme.Translucent”>
<item name=”android:windowBackground”>@drawable/translucent_background</item>
<item name=”android:windowNoTitle”>true</item>
<item name=”android:colorForeground”>#fff</item>
</style>

<!– Variation on our application theme that has a transparent background; this example completely removes the background, allowing the activity to decide how to composite. –>
<style name=”Theme.Transparent”>
<item name=”android:windowBackground”>@drawable/transparent_background</item>
<item name=”android:windowNoTitle”>true</item>
<item name=”android:colorForeground”>#fff</item>
</style>
<style name=”TextAppearance.Theme.PlainText” parent=”android:TextAppearance.Theme”>
<item name=”android:textStyle”>normal</item>
</style>
</resources>

This is how you will reference your resource:

public class WidgetActivity extends Activity {
@Override protected void onCreate(Bundle bundle) {
super.onCreate(bundle);

Log.i(Global.TAG2, “sub-Activity WidgetActivity being creation: start”);
setTheme(R.style.Theme_Translucent);
setContentView(Panel2Builder.createWidgetPanel(this));
Log.i(Global.TAG2, “sub-Activity WidgetActivity being creation: end”);
}
}//end class WidgetActivity

Resource located at: developerlife.com

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here