Here you can find the source of getStatusbarHeight(Activity activity)
public static int getStatusbarHeight(Activity activity)
//package com.java2s; import android.app.Activity; import android.content.Context; import android.graphics.Rect; import android.util.DisplayMetrics; public class Main { public static final int UI_DEFAULT_STATUSBAR_HEIGHT = 24; public static int getStatusbarHeight(Activity activity) { int statusbarHeight; try {/*from ww w . j ava 2 s .c o m*/ Rect frame = new Rect(); activity.getWindow().getDecorView() .getWindowVisibleDisplayFrame(frame); statusbarHeight = frame.top; } catch (Exception e) { statusbarHeight = getDensityDimen(activity, UI_DEFAULT_STATUSBAR_HEIGHT); } return statusbarHeight; } public static int getDensityDimen(Context context, int dimen) { final DisplayMetrics dm = context.getResources() .getDisplayMetrics(); return ((int) (dimen * dm.density)); } }