Skip to content

Instantly share code, notes, and snippets.

@kuloud
Created June 19, 2014 08:59
Show Gist options
  • Select an option

  • Save kuloud/07847727549486b0e48c to your computer and use it in GitHub Desktop.

Select an option

Save kuloud/07847727549486b0e48c to your computer and use it in GitHub Desktop.
Get status bar height
public int getStatusBarHeight(Context context){
Class<?> c = null;
Object obj = null;
Field field = null;
int x = 0, statusBarHeight = 0;
try {
c = Class.forName("com.android.internal.R$dimen");
obj = c.newInstance();
field = c.getField("status_bar_height");
x = Integer.parseInt(field.get(obj).toString());
statusBarHeight = context.getResources().getDimensionPixelSize(x);
} catch (Exception e1) {
e1.printStackTrace();
}
return statusBarHeight;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment