Height of status bar can be read by following way. (can be found easily by Googling - ex. stack-overflow)


Rect rect= new Rect();

Window window= activity.getWindow();

window.getDecorView().getWindowVisibleDisplayFrame(rect);

return rect.top;


But, even after hiding status bar by adding LayoutParams.FLAG_FULLSCREEN at onCreate() or onResume(), height of status bar read by above way, may be still invalid (Not 0).

(I didn't analyze deeply about WindowManager. So, I'm not sure about root cause - due to animation effect??? or something else???)

To workaround this issue, the best place to read height of status bar - hidden or shown - is onWindowFocusedChanged().

Reading height of status bar at the first call of onWindowFocusedChanged() gives exact(expected) value based on my experience.

And then, this value can be reused afterward.


+ Recent posts