Translucent Full Screen problems
2010-04-29 13:50:19
Added toggling of full screen mode to my app today. It wasn't as simple as I had first thought. As always, there're several ways of doing it. The most basic way is to use one of the predefined themes. For instance add the following XML-property to your activity or app:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
This will have the (dis)advantage of also removing the title bar. If you for some reason want full screen and title bar, you have to define your own theme. The android dev-site has more documentation on applying themes and styles . It also helps to have a look in the source files defining the themes. These are found in the sdk, for instance:
android-sdk-linux_86/platforms/android-2.1/data/res/values/themes.xml
But as I wanted to be able to toggle the fullscreen i needed to set it in code. So I proceeded to add the following function in my activity class:
void toggleFullscreen() {
if (mFullscreen) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
mFullscreen=false;
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
mFullscreen=true;
}
}
to be called in order to toggles the screen mode. Happily thinking job done, I launched my app in the emulator only to find this:
The fullscreen mode did indeed use the whole screen, but the statusbar was laid on top of it, instead of being hidden as I had expected.
The problem as it turns out was the the app had a translucent window background (it used the theme Theme.Translucent.NoTitleBar). This can be seen in the screen shot that the background isn't opaque, the home screen can be seen through it. The background color of the layout is set to c000.
To find out if this was a general problem, I also tried applying a theme that had the translucent and full screen parameters set. Turns out there is such a theme pre-defined:
android:theme="android:style/Theme.Translucent.NoTitleBar.Fullscreen"
This had the same effect as toggeling the fullscreen off, so it seems to be an inherent problem with mixing fullscreen mode and translucency. As a corollary this theme is only useful for an activity whuch is always on top of some other opaque fullscreen activity. That is, if an activity A in fullscreen mode, launches another activity B. The translucent fullscreen theme will work fine for the B, provided that A is not also translucent.
I was seeing this on android 2.1, but I've seen other posts that describes the same problem on 1.5 so I assume it is not version specific (at least not from 1.5 and forward).
So in conclusion it seems one must chose either fullscreen or translucency, can't have both. At least not for the main activity. Hmm, bummer.
Update: also tried setting the background drawable of the window to to make it transparent:
getWindow().setBackgroundDrawable(new ColorDrawable(0));
According to the documentation this should make the window transparent, but for me it had no effect whatsoever...
Posted by android 2
0 CommentsPage 1