Skip to content

Instantly share code, notes, and snippets.

@billyjoker
Forked from hamakn/height.java
Created November 14, 2018 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billyjoker/4215c702c1d64b91c15f7f6d62b9f656 to your computer and use it in GitHub Desktop.
Save billyjoker/4215c702c1d64b91c15f7f6d62b9f656 to your computer and use it in GitHub Desktop.
Android: Get height of status, action, navigation bar (pixels)
// status bar height
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
// action bar height
int actionBarHeight = 0;
final TypedArray styledAttributes = getActivity().getTheme().obtainStyledAttributes(
new int[] { android.R.attr.actionBarSize }
);
actionBarHeight = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();
// navigation bar height
int navigationBarHeight = 0;
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
navigationBarHeight = resources.getDimensionPixelSize(resourceId);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment