I'm having a strange issue with figuring out the height of the ActionBar
. I have a couple of parts in my app where something is positioned right below the ActionBar
, and I'm also using Chris Banes' library actionbar-pulltorefresh.
I'll use the example from the pull to refresh library. I'm experiencing the exact same thing as the issue here, except I'm doing everything exactly how the guide says to with Fragments
. It basically calculates the height of the ActionBar
to be about half of what it should be. Also in a different part of the app, I'm positioning a PopupWindow
below the ActionBar
, so I call the getHeight()
and use that position for my window, I get the same issue as with the pull to refresh library.
So that makes me think it's something to do with how the ActionBar
height is measured, and it may possibly be a style issue.
But here's where it gets interesting. If I rotate the devices to landscape mode, it figures the height fine and puts everything where it should be from that point on, even if I rotate back to portrait. it's suddenly fixed until I restart the app and kill it from memory and start fresh again.
Anyone had anything similar happen?
NOTE: I'm using the appcompat library now, but I was using ActionBarSherlock before, as well as the basic ActionBar at some point, and all scenarios gave the same result.
UPDATE 1: I get the same results from the issues here, here, and here. However I'm doing everything the README says to do so I'm fairly confident it's something to do with how my device measures the ActionBar
height.
UPDATE 2: I used the actionbar PullToRefresh library in another activity and it works fine, so it must be something to do with my main Activity
.
The Toolbar (if not extended) has the height of: 56dp (default)
android:attr/actionBarSize" means: "the size (height) of the action bar".
In order to make sure there aren't Views under your Action Bar, you can add a top margin to it in the XML.
<SomeView
...
android:layout_marginTop="?android:attr/actionBarSize" />
Source: http://developer.android.com/guide/topics/ui/actionbar.html#Style
UPDATE: The following is added on. I decided to dive into the Android source code to see what the actual ActionBar heights are supposed to be. So, I looked in all the different types of values/dimens.xml to find action_bar_default_height
. Below are the findings.
In values/dimens.xml,
<!-- Default height of an action bar. -->
<dimen name="action_bar_default_height">48dip</dimen>
In values-land/dimens.xml,
<!-- Default height of an action bar. -->
<dimen name="action_bar_default_height">40dip</dimen>
In values-sw600dp/dimens.xml,
<!-- Default height of an action bar. -->
<dimen name="action_bar_default_height">56dip</dimen>
I also checked the following, but they don't overwrite this attribute:
values-large
values-sw380dp
values-sw600dp-land
values-sw720dp
values-w360dp
values-w600dp
values-w720dp
values-xlarge
When I get more time, I may look for the root of the problem, but until then you can add these three values in your different values folders (as a temp fix).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With