New Theme.AppCompat ActionBar height

15,931

There's no workaround needed. If you're using ?android:attr/actionBarSize android will look up the value in the plattform you're currently using. The result will be 48dp if you're running an Android-Version below 5.0, obviously.
Since you're using the appcompat-v7 library in your project you should use ?actionBarSize. This will return 56dp as expected, because the system will look up the value in your project, which has the actionBarSize defined because of the appcompat-library.

If you wanna try this on your own, here's a little code-snippet to test the described behaviour:

int[] textSizeAttr = new int[] { android.R.attr.actionBarSize, R.attr.actionBarSize };
TypedArray a = obtainStyledAttributes(new TypedValue().data, textSizeAttr);
float heightHolo = a.getDimension(0, -1);
float heightMaterial = a.getDimension(1, -1);

Log.d("DEBUG", "Height android.R.attr.: " + heightHolo + "");
Log.d("DEBUG", "Height R.attr.: " + heightMaterial + "");

Note: This will return the size in pixels. As an example on my Nexus 5, which is running 4.4 at the moment, it returns 144px(48dp) for android.R.attr.actionBarSize and 168px (56dp) for R.attr.actionBarSize.

Share:
15,931
Egor Neliuba
Author by

Egor Neliuba

Updated on August 16, 2022

Comments

  • Egor Neliuba
    Egor Neliuba almost 2 years

    When using version 21 of appcompat library, ?android:attr/actionBarSize returns 48 dips as if it was Holo theme and not Material. In fact it's a bit bigger - 56 dips.

    Has anyone found a workaround for this issue?