Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out if ActionBar is stacked

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.

Youtube App (landscape)Youtube App (portrait)

like image 285
Julian Avatar asked Jan 29 '12 10:01

Julian


2 Answers

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.

like image 115
Jin35 Avatar answered Nov 14 '22 08:11

Jin35


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".

Mock-ups of split action bar with navigation tabs on the left; with the app icon and title disabled on the right.

You can get more details here.

like image 1
Thiago M Rocha Avatar answered Nov 14 '22 07:11

Thiago M Rocha