windowIsFloating=true & window size

Search This thread


Apr 13, 2006
I'm developing an activity with a floating main window (e.g. windowIsFloating=true in the activity style). Unfortunately, within a floating window my layout (using fill_parent) is not expanded to the full screen size; fill_parent behaves like wrap_content instead. I suppose floating windows are not automatically sized to the regular/maximized window size.

To circumvent this problem, I use the following code to add the layout to my window:
View view = getLayoutInflater().inflate(R.layout.main, null);
setContentView(view, new LayoutParams(width, height));

This renders my layout correctly. However, how do I find out the correct width and height, taking into account decorations like the status bar? According to the documentation, floating windows automatically get the FLAG_LAYOUT_INSET_DECOR set, causing the WindowManager to report inset rectangle needed to ensure the content is not covered by screen decorations. However, I can't find any documentation on how I can retrieve this inset rectangle; does anyone know this?

I've tried many options (all called from my Activity onCreate method), but they all either return non-usefull information or the full screen size, not taking into account the status bar height:

WindowManager.LayoutParams lp = (WindowManager.LayoutParams)getWindow().getAttributes();
Rect rect = getWindow().getDecorView().getBackground().getBounds();

I'm now using a work-around that simply substracts 38 from the height to account for the status bar, but of course that's not a real solution.

Also, does anyone know whether it is possible to hide or overlay the status bar when using a floating window? Setting windowFullScreen=false only works correctly for non-floating windows.


Senior Member
Mar 5, 2011
I believe you can set the theme in xml to remove the status bar in your app.

<activity android:name=".YourClassName" android:theme="@android:style/Theme.NoTitleBar"/>


<activity android:name=".YourClassName" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

From something awesome
Last edited: