0

I need to set a View's topMargin by the Actionbar height so it's visible under the Actionbar. I do this in my onCreateOptionsMenu, thinking the Actionbar is drawn at that point. My app targets API 14 and above only.

Running an emulator with API 17, getHeight() returns a good value of 96dp. But running the same code on an emulator with API 16, a height of zero is returned, likely because it hasn't been drawn yet.

Why would there be a difference between the two APIs?

mraviator
  • 4,034
  • 9
  • 38
  • 51
  • You can try to get the height only when view is drawn. See http://stackoverflow.com/a/8171014/1306419 to see how to listen for when the view is actually drawn. – Shobhit Puri Aug 30 '13 at 17:28

1 Answers1

0

Read it from:

?android:attr/actionBarSize

Check this post for more information:

What is the size of ActionBar in pixels?

Community
  • 1
  • 1
Juangcg
  • 1,038
  • 9
  • 14