Get the ActionBar size in pixel. - Android User Interface

Android examples for User Interface:ActionBar

Description

Get the ActionBar size in pixel.

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.res.TypedArray;

public class Main {
    /**//from  w w  w.j  ava  2  s .  c o m
     * Get the action bar size in pixel.
     *
     * @param context the {@link android.content.Context} used to retrieve the theme.
     * @return
     */
    public static int getActionBarSize(Context context) {
        final TypedArray styledAttributes = context.getTheme()
                .obtainStyledAttributes(
                        new int[] { android.R.attr.actionBarSize });
        final int actionBarSize = (int) styledAttributes.getDimension(0, 0);
        styledAttributes.recycle();
        return actionBarSize;
    }
}

Related Tutorials