Java tutorial
//package com.java2s; //License from project: Apache License import android.app.Activity; import android.content.Context; import android.os.Build; import android.util.TypedValue; public class Main { /** * get action bar height * * @param context * @return */ public static int getActionBarHeight(Context context) { int actionBarHeight = 0; if (context instanceof Activity && ((Activity) context).getActionBar() != null) { actionBarHeight = ((Activity) context).getActionBar().getHeight(); } if (actionBarHeight == 0) { final TypedValue tv = new TypedValue(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && (context.getTheme() != null && context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))) { actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics()); } } return actionBarHeight; } }