NathanZ NathanZ - 4 months ago 5x
Android Question

How to get the ActionBar height?

I am trying to get the height of the

(using Sherlock) every time an activity is created (specially to handle configuration changes on rotation where the ActionBar height might change).

For this I use the method
which works only when the
is shown.

When the first activity is created for the first time, I can call
in the
callback. But this method is not called after.

So my question is when can I call getHeight() and be assured that it doesn't return 0?
Or if it is not possible, how can I set the height of the ActionBar ?


While @birdy's answer is an option if you want to explicitly control the ActionBar size there is a way to pull it up without locking the size that I found in support documentation. It's a little awkward but it's worked for me. You'll need a context, this example would be valid in an Activity.

// Calculate ActionBar height
TypedValue tv = new TypedValue();
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
    actionBarHeight = TypedValue.complexToDimensionPixelSize(,getResources().getDisplayMetrics());