Created
April 6, 2016 18:12
-
-
Save mrhether/7aa1bb7072df362c5692f9ca119b9a7e to your computer and use it in GitHub Desktop.
Window Utils Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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