i have an action bar with a Tab navigation. While running on 3.1 everything was fine, but once i installed the app on a 4.1 device the tabs where forced to be displayed as a spinner, wrecking my layout design. Looks like the tabs are taking too much space (if i remove some of the fragments everyting looks ok again. Is there a way to stop this behaviour and display the navigation as tabs again just as in android 3.1? Does anyone know?
thanks!
First of, just to clarify: This is not a bug and it works as intended. Reference this discussion on the Google code forums.
However, I came to the solution that if you override:
You won't have a
NAVIGATION_MODE_LIST
in portrait mode. However you won't have embedded tabs and if you rotate your screen to landscape it won't work either. By default you'll have embedded tabs and therefore aNAVIGATION_MODE_LIST
on a screen with a width of >480dp.This behavior occurs (I assume) because the embedded tabs are limited to the width of the ActionBar, so if you override the boolean value it'll have tabs in a separate row and it won't collapse. But unfortunately I can't explain myself why this does not work in landscape.
Sorry, but you can't stop this. This is a feature, not a bug, according to Google. See: http://code.google.com/p/android/issues/detail?id=24439
As I understand you should consider using a ViewPager + PagerTitleStrip if you have many tabs and want to make them scrollable all time. Here is a quote from ttps://code.google.com/p/android/issues/detail?id=24439#c9:
I would not recommend using tricks as nobody guarantee that tricks will works stable.
If you really want to still use tabs and stop it from collapsing to a spinner, it is technically possible using reflection IF you happen to be setting a customView for the tabs:
If there is not enough space, the tabs will scroll in the ActionBar. The Tabs and any Menu actionItems are given 1/2 the screen width so you can calculate if the tabs will end up scrolling or not and make adjustments to tabs, menu actionItem labels etc or force the tabs into a stacked mode to avoid the scrolling tabs... OR as previously suggested, using the PagerTitleStrip instead.
I found the answer here. Had to set the navigation mode AFTER adding the tabs.