Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.graphics.Point; import android.view.Display; import android.view.WindowManager; import java.lang.reflect.Field; public class Main { public static int getScreenHeightExceptStatusBar(Context context) { return getScreenHeigth(context) - getStatusBarHeight(context); } /** * @return return screen height px unit. */ public static int getScreenHeigth(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); return size.y; } public static int getStatusBarHeight(Context context) { Class<?> c; Object obj; Field field; int x, 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; /** * Rect frame = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; */ } }