Tuesday, 27 September 2011

Android: Creating a transparent/translucent applications (activity)

Recent posts:
Android: Localizing your Android app - Part 1
Android: displaying widgets in a grid-like layout
Android: displaying widgets in a grid-like layout - Part 2, The TableLayout
Android: Getting all and maximum megapixels supported by the camera
Android: Taking pictures without a preview window
Android: Sending emails without user intervention

I get this question all the time and the solution is very simple.
Just set the theme of the app to one of the following:

  • Theme.Translucent
  • Theme.Translucent.NoTitleBar
  • Theme.Translucent.NoTitleBar.Fullscreen

To do that, just edit the manifest file and add, in the application section, android:theme="@android:style/Theme.Translucent" (or any of the above)

for instance
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent">

This will make your app look like this

Theme.Translucent.NoTitleBar and Theme.Translucent.NoTitleBar.Fullscreen  produce

I think Theme.Translucent.NoTitleBar.Fullscreen was supposed to hide the system's status bar but what happens is that the status bar is never hidden. When using any of the *Fullscreen themes, the app window just extends on top of the status bar.

Have fun.

Programming tricks and tips for android developers