0

There are Android devices that have status bar at the bottom of the screen. So if I count absolute position including the height of status bar at these devices, the layout will be ruined.

Is there a way to determine the position of the status bar, if it's at the top of bottom of the screen?

Dombi Bence
  • 746
  • 7
  • 23

2 Answers2

5

Below code works for me. I just found it from an answer in another question.

public static int getTopStatusBarHeight(Activity activity) {
    Rect rect = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
    return rect.top;
}

If result of this method is 0, it means the status bar is at the bottom, and otherwise.

Community
  • 1
  • 1
Ngoc Nguyen
  • 66
  • 2
  • 3
0

Essentially it can't be done. Their position is absolute. You can hide/unhide them. But you can't move them. You can however split them:
http://developer.android.com/guide/topics/ui/actionbar.html
Then this link shows you how you can hide/unhide some of the bars:
http://developer.android.com/training/system-ui/status.html

hipkiss
  • 197
  • 2
  • 19
  • Thank you for your answer, however the figure you linked only contains element names for colors. I don't really understand how I could you this to get the position of status bar. – Dombi Bence Oct 19 '15 at 12:37