Getting the height of STATUS BAR
android, height, java, statusbar
Solution
Just searched the site for a while and got this.
private int statusBar() {
Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop=
window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int statusBar = contentViewTop - StatusBarHeight;
return statusBar;
}
The toast:
Toast.makeText(getApplicationContext(), "" + statusBar(), Toast.LENGTH_LONG).show();
It seems working.
update:
try this, if didn't work try the other one.
private int statusBar() {
Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int statusBar = rectgle.top;
return statusBar;
}
2nd
private int statusBar() {
Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop=
window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int statusBar = contentViewTop + StatusBarHeight;
return statusBar;
}
Problem
I'm tring to write a `private` to get the `status bar's` height. ``` private int statusBar() { Rect rect = new Rect(); int statusBar = rect.top; return statusBar; } ``` Everything is good till now. but when I do: ``` Toast.makeText(getApplicationContext(), "" + statusBar(), Toast.LENGTH_LONG).show(); ``` It returns 0.