The Nexus
Show navigation Hide navigation
  • BLOG
  • ABOUT
    • Ego Surfing
  • PROJECTS
    • n2
    • S2ajax
    • Condo
    • ezEdit
    • FreeBlog - Air
    • Tooredo Alpha
    • Tools
    • Journlr, Again!
8 Nov 2011 | 1 min. (129 words)

Android StatusBar Height, the cautious way

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.

RootTools 1.5, NativeTools 1.0

A fast, low-memory growable array for Android

2022 The Nexus