Tuesday, August 24, 2010

Providing your Android Activity with a Theme

I've recently been asked a couple of times by new Android developers how 'Tech Buzz Widget' manages to overlay itself ontop of the desktop, allowing your wallpaper to show through. Assuming that it is easier to Google the answer than ask me, it may be somethiing that there isn't enough detail on already. So here is my 10 cents.

The main detail is to set the correct android:theme for your activity in the AndroidManifest.xml. For Tech Buzz Widget we used android:theme="@android:style/Theme.Translucent.NoTitleBar"

So the activity looked like this:

<activity android:name=".FullArticleView" class=".FullArticleView"
<action android:name="android.intent.action.MAIN" />

Once you've done that you you'll see that any elements of your layout that are transparent or unfilled will show through onto the underlying application or desktop. To make this more obvious in Tech Buzz we put a margin around the entire layout.

The exact details of all the activity themes available in the current Android platform are available in the Android source here: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/themes.xml

Search for Theme.Translucent and you'll get the idea. There are fullscreen themes as well if you want to get rid of the notification bar. You can also define your own themes in a similar way.