get Action Bar Height In Dp - Android User Interface

Android examples for User Interface:ActionBar

Description

get Action Bar Height In Dp

Demo Code


//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();/*  w w w.j a va  2s . co  m*/
        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;
    }
}

Related Tutorials