Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Theme.AppCompat ActionBar height

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?

like image 471
Egor Neliuba Avatar asked Oct 19 '14 09:10

Egor Neliuba


People also ask

How to import appcompat to workspace?

On step 1 (File->Import (android-sdk\extras\android\support\v7). Choose "appcompat"), one needs to check "copy to workspace". I faced with similar problem. Thanks a lot, it was really tricky

How to fix appcompat_v7 errors?

SO just check whether your "appcompat_v7" is not closed. If it is then open the project by double click and then clean and build your project again. In my case the errors were gone. Happy coding!

How do I add an appcompat resource to my Android project?

Choose "AppCompat" Project-> properties->Android. In the section library "Add" and choose "AppCompat" That is all! This does not work for me. I do exactly what is written here, but end up with hundred of No resource found that matches given name errors.

How do I start a project in R with appcompat_v7?

Support library "appcompat_v7" and your project should be in a same directory (I mean workspace directory). Dont clean your project until its error free else you will have tough time with R.java You had better make new project with any name , then use appcompat_v7 that program make new . In the section library Add and choose library appcompat.


1 Answers

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.

like image 153
reVerse Avatar answered Oct 18 '22 17:10

reVerse