A
lot of applications expect the status bar to be at the top of your device’s
screen. It’s true in most cases so their developers are somewhat justified in
making this assumption.
However, with more and more tablets on the market, this is becoming an
increasingly dangerous assumption.
Also somewhat dangerous: the notion that your status bar’s height will be (your visible area’s height - zero). Google never made any commitment that the status bar will always start at pixel zero.
So, here is how I do it:
Rect outerRect = new Rect();
Rect usableRect = new Rect();
Window window= Home.getInstance().getWindow();
window.getDecorView().getGlobalVisibleRect(outerRect);
window.getDecorView().getWindowVisibleDisplayFrame(usableRect);
statusBarHeight = usableRect.top - outerRect.top;
// Sometimes, status bar is at bottom...
int bottomGap = outerRect.bottom - usableRect.bottom;
if(bottomGap > statusBarHeight) {
statusBarHeight = bottomGap;
}
Comments powered by Talkyard.