Skip to content

Instantly share code, notes, and snippets.

@lugeek
Created March 23, 2017 13:10
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 lugeek/808146a6428d669da2da0a66a042f321 to your computer and use it in GitHub Desktop.
Save lugeek/808146a6428d669da2da0a66a042f321 to your computer and use it in GitHub Desktop.
getStatusBarHeight
public static 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