Q: Height of status bar in Android

Test Case #11


File ID: #3410200-0-cc


   public static int getStatusBar(Activity activity) {
    Rect rectgle = new Rect();
    Window window = activity.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
    int StatusBarHeight = rectgle.top;
    int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT)
                         .getTop();
    int TitleBarHeight = contentViewTop - StatusBarHeight;
    Log.i("Layout.getStatusBar", "StatusBar Height= " + StatusBarHeight
          + " , TitleBar Height = " + TitleBarHeight);
    return contentViewTop;
}

  1. Didn't work in onCreate
  2. Or use dip? If it always has 25dip then the code is not needed.
  3. you can't assume it's always 25dp (check out the height for example on the kindle fire).

Comments Quality
Accurate?:
Precise?:
Concise?:
Useful?: