Java tutorial
//package com.java2s; import android.content.Context; import android.util.Log; import java.lang.reflect.Field; public class Main { public static int getStatusBarHeight(Context context) { Class<?> c = null; Object obj = null; Field field = null; int x = 0, sbar = 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()); sbar = context.getResources().getDimensionPixelSize(x); } catch (Exception e1) { Log.e("getStatusBarHight()", "get status bar height fail"); e1.printStackTrace(); } int statusBarHeight = sbar; Log.i("onPreDraw", "statusBarHeight: " + statusBarHeight); return statusBarHeight; } }