When in multi-window mode, Window height does not include status bar height

1k views Asked by At

My activity draws under the status bar, which is translucent.

I am getting the window height using:

WindowManager manager = activity.getWindowManager();
DisplayMetrics metrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels;

This height is correct, in that includes the content height and the status bar height, since I’m drawing there and my window has the correct flags.

When in multi-window mode, in Nougat, if my app is the top one, it is still drawing under the status bar, but height will not include that value.

How do I get the real window height in multi-window mode without getting dirty?

Note

I don’t want the screen height, as returned e.g. by Display.getRealSize(). I want the Window height. But if my window draws under the status bar, the value must include the status bar height, as it does when multi-window is off.

More info

Actually, after going multi-window, the height value will never have the status bar included, even if you exit multi-window after. For instance, on a Nexus5X:

// Start the app in normal mode
height = 1794; // Everything except nav bar. OK!
// Go in multi-window mode.
// Go out of multi-window mode.
height = 1730; // Status bar height is not there anymore. :-(

Seems like a dirty dirty bug. In that case I wonder if anyone knows more about it (devices, API levels, bug report).

1

There are 1 answers

0
Bö macht Blau On BEST ANSWER

There is an AOSP Issue (219133) about problems with the Display class when using multi-window mode in the Android 7.0 preview.

The development team states they fixed the error and the patch "will be available in future releases". So far (version 7.0 and 7.1), the buggy behavior persists.