Eugene Eugene - 3 years ago 128
Android Question

What is the size of ActionBar in pixels?

I need to know the exact size of ActionBar in pixels so to apply correct background image.

Answer Source

To retrieve the height of the ActionBar in XML, just use


or if you're an ActionBarSherlock or AppCompat user, use this


If you need this value at runtime, use this

final TypedArray styledAttributes = getContext().getTheme().obtainStyledAttributes(
                    new int[] { android.R.attr.actionBarSize });
mActionBarSize = (int) styledAttributes.getDimension(0, 0);

If you need to understand where this is defined:

  1. The attribute name itself is defined in the platform's /res/values/attrs.xml
  2. The platform's themes.xml picks this attribute and assigns a value to it.
  3. The value assigned in step 2 depends on different device sizes, which are defined in various dimens.xml files in the platform, ie. core/res/res/values-sw600dp/dimens.xml
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download