If you add tabs to your ActionBar
, they will be in an extra stacked ActionBar
on phones in portrait mode. Is there an easy way to find out whether this happened?
I've attached two screenshots of the YouTube app. The first one shows the normal ActionBar
with the tabs in it, the second one shows the tabs in a stacked ActionBar
.
It is possible to find out if there is one or two lines in action bar by is's height. There is method getHeight()
, but it will not work in onCreate
or onStart
, it will return real value only if activity already started.
In landscape orientation height of action bar is 40dip
(80/60/40/30 px on different screens), in portrait orientation with tabs it is 96dp (192/144/96/72 px).
It is not the best idea to rely on this, but I can't find any other way to find out if tabs is inside action bar.
This behavior is called Split Action Bar. It happens when the AndroidManifest
is set with uiOptions="splitActionBarWhenNarrow"
in the <activity>
or <application>
element.
Android adjusts the action bar's appearance in a variety of ways, based on the current screen size. Using split action bar is just one option that you can enable to allow the action bar to further optimize the user experience for different screen sizes. In doing so, you may also allow the action bar to collapse navigation tabs into the main action bar. That is, if you use navigation tabs in your action bar, once the action items are separated on a narrow screen, the navigation tabs may be able to fit into the main action bar rather than be separated into the "stacked action bar".
You can get more details here.
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