Created
February 24, 2015 20:29
-
-
Save Kozlov-V/2bcbd88f67c48748f911 to your computer and use it in GitHub Desktop.
get Status Bar Heigh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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