Java tutorial
//package com.java2s; import android.content.Context; import android.os.Build; import android.os.Build.VERSION_CODES; import android.util.DisplayMetrics; import android.util.TypedValue; public class Main { public static int getActionBarHeightInDp(Context context) { int actionBarHeight = 0; TypedValue tv = new TypedValue(); final DisplayMetrics dm = context.getResources().getDisplayMetrics(); if (Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) { if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) actionBarHeight = (int) TypedValue.complexToFloat(tv.data); } else { tv.data = 48; actionBarHeight = (int) TypedValue.complexToFloat(tv.data); } return actionBarHeight; } }