Skip to content

Instantly share code, notes, and snippets.

@ninthdrug
Created July 13, 2015 10:37
Show Gist options
  • Save ninthdrug/1130f64f27c0df90c2fd to your computer and use it in GitHub Desktop.
Save ninthdrug/1130f64f27c0df90c2fd to your computer and use it in GitHub Desktop.
android status bar height
DisplayMetrics displayMetrics = new DisplayMetrics();
((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics);
int statusBarHeight;
switch (displayMetrics.densityDpi) {
case DisplayMetrics.DENSITY_HIGH:
statusBarHeight = HIGH_DPI_STATUS_BAR_HEIGHT;
break;
case DisplayMetrics.DENSITY_MEDIUM:
statusBarHeight = MEDIUM_DPI_STATUS_BAR_HEIGHT;
break;
case DisplayMetrics.DENSITY_LOW:
statusBarHeight = LOW_DPI_STATUS_BAR_HEIGHT;
break;
default:
statusBarHeight = MEDIUM_DPI_STATUS_BAR_HEIGHT;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment