Java tutorial
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; import android.app.Activity; import android.view.Display; public class Main { public static int getStatusBarHeight(Activity activity) { int statusBarHeight = 0; if (!hasOnScreenSystemBar(activity)) { int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) statusBarHeight = activity.getResources().getDimensionPixelSize(resourceId); } return statusBarHeight; } @SuppressWarnings("deprecation") private static boolean hasOnScreenSystemBar(Activity activity) { Display display = activity.getWindowManager().getDefaultDisplay(); int rawDisplayHeight = 0; try { Method getRawHeight = Display.class.getMethod("getRawHeight"); rawDisplayHeight = (Integer) getRawHeight.invoke(display); } catch (Exception ex) { } int uiRequestedHeight = display.getHeight(); return rawDisplayHeight - uiRequestedHeight > 0; } }