Suman’s Blog

Android Application Development

Android Themes

Posted by Suman on April 5, 2009

A theme is a set of one or more UI formatting attributes, which can be applied to whole application or specifically to an activity.

Let us take a look at default themes supplied with Android SDK. Below themes will control the background, status bar and title bar.

Status bar: Visible

Status bar: Visible

Status bar: Invisible

Title bar: Visible

Title bar: Invisible

Title bar: Invisible

Theme

Theme.NoTitleBar

Theme.NoTitleBar.Fullscreen

Theme.Black

Theme.Black.NoTitleBar

Theme.Black.NoTitleBar.Fullscreen

Theme.Light

Theme.Light.NoTitleBar

Theme.Light.NoTitleBar.Fullscreen

Theme.Translucent

Theme.Translucent.NoTitleBar

Theme.Translucent.NoTitleBar.Fullscreen

Theme:Dialog By using this theme your activity will have feel of dialog. That’s how you can build dialogs with your application’s look.

Theme can be defined either at application level or at activity level.

  • Application level: by defining theme in manifest under application tag. This theme will be applicable to all activities in this application.

<application

android:icon=“@drawable/icon”

android:label=“@string/app_name”

android:theme=“@android:style/Theme.Translucent:NoTitleBar” >

  • Activity level: This can be done in manifest or java code. The theme will be applicable to this activity only.

In manifest: Set the theme in manifest under activity tag.

<activity

android:name=“.Welcome”

android:label=“@string/app_name”

android:theme=“@android:style/Theme.Translucent.NoTitleBar” >

In java code: You can set theme in onCreate method.

@Override

public void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);

setTheme(android.R.style.Theme_Translucent_NoTitleBar);

setContentView(R.layout.main);

}

The above discussion was about the themes which comes with Android SDK. Now the question is can we define our own theme???

And the answer is yes, you need to define this set of attribute to make up a complete theme.

<?xml version=“1.0” encoding=“utf-8″?>

<resources>

<style name=“MyTheme”>

HERE DEFINE ALL THE ATTRIBUTES

</style>

This conclude my article about Android themes.

Posted in Android | Tagged: , , , , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.