Skip to content

Instantly share code, notes, and snippets.

@markus2610
Created August 6, 2014 14:48
Show Gist options
  • Select an option

  • Save markus2610/0933e98e82a20541f06b to your computer and use it in GitHub Desktop.

Select an option

Save markus2610/0933e98e82a20541f06b to your computer and use it in GitHub Desktop.
public static int getDimensionForName(String resourceName, Context ctx) {
int result = 0;
int resourceId = ctx.getResources().getIdentifier(resourceName, "dimen", "android");
if (resourceId > 0) {
result = ctx.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
public static int getNotificationBarHeight(Context ctx) {
return getDimensionForName("status_bar_height", ctx);
}
public static int getNavigationBarHeight(Context ctx) {
return getDimensionForName("navigation_bar_height", ctx);
}
public static int getActionBarHeight(Context ctx) {
return (int) ctx.getResources().getDimension(R.dimen.abc_action_bar_default_height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment