Skip to content

Instantly share code, notes, and snippets.

@mrhether
Created April 6, 2016 18:12
Show Gist options
  • Save mrhether/7aa1bb7072df362c5692f9ca119b9a7e to your computer and use it in GitHub Desktop.
Save mrhether/7aa1bb7072df362c5692f9ca119b9a7e to your computer and use it in GitHub Desktop.
Window Utils Android
public class WindowUtils {
public static int getActionBarHeight(Context context) {
final TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(
new int[]{R.attr.actionBarSize});
int actionBarHeight = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();
return actionBarHeight;
}
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
public static int getScreenHeight(Activity context) {
Display display = context.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
return size.y;
}
public static int getScreenWidth(Activity context) {
Display display = context.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
return size.x;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment