Skip to content

Instantly share code, notes, and snippets.

@Kozlov-V
Created February 24, 2015 20:29
Show Gist options
  • Save Kozlov-V/2bcbd88f67c48748f911 to your computer and use it in GitHub Desktop.
Save Kozlov-V/2bcbd88f67c48748f911 to your computer and use it in GitHub Desktop.
get Status Bar Heigh
public int getStatusBarHeight() {
int statusBarHeight = 0;
if (!hasOnScreenSystemBar()) {
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
}
return statusBarHeight;
}
private boolean hasOnScreenSystemBar() {
Display display = getWindowManager().getDefaultDisplay();
int rawDisplayHeight = 0;
try {
Method getRawHeight = Display.class.getMethod("getRawHeight");
rawDisplayHeight = (Integer) getRawHeight.invoke(display);
} catch (Exception ex) {
}
int UIRequestedHeight = display.getHeight();
return rawDisplayHeight - UIRequestedHeight > 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment