Skip to content

Instantly share code, notes, and snippets.

@Suchiq
Created May 4, 2020 16:26
Show Gist options
  • Save Suchiq/2ef2d0d655ed21196c614c64e34adb3e to your computer and use it in GitHub Desktop.
Save Suchiq/2ef2d0d655ed21196c614c64e34adb3e to your computer and use it in GitHub Desktop.
Calculate status bar height
public static int getStatusBarHeight() {
int statusBarHeight = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int resourceId = getContext().getResources()
.getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getContext().getResources()
.getDimensionPixelSize(resourceId);
}
}
return statusBarHeight;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment