Android & Wordpress Help center

Archive for the month “July, 2013”

How to get Height/Width of android screen?

The code snippet below helps you to determine the Height and Width of android screen:

Code before API 13

WindowManager wm = (WindowManager) .getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
this.width = display.getWidth();
this.height = display.getHeight();

Code for API 13+

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
int width = size.x;
int height = size.y;

This code will give you height of the window along with the status bar. If you want to exclude the height of status bar you can simply deduct it from the height of the entire window. Following code helps you determine the height of status bar:

Code to get height of status bar

public int getStatusBarHeight() {
int height = 0;
int resourceId = getResources().getIdentifier(“status_bar_height”, “dimen”, “android”);
if (resourceId > 0) {
height = getResources().getDimensionPixelSize(resourceId);

return height;


Post Navigation