1

I am using ActionBarSherlock to implement 4 tabs in an activity. The tabs display properly in portrait mode below the action bar and scrolling works as it should. When I switch to landscape mode, the tabs are placed in a spinner (they still function correctly). How can I force the tabs to display individually in landscape mode (either in the action bar or below)?

    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);


    ActionBar.Tab tab1 = getSupportActionBar().newTab();
    tab1.setText("TAB 1 TEXT");
    tab1.setTabListener(this);
    getSupportActionBar().addTab(tab1);

    ActionBar.Tab tab2 = getSupportActionBar().newTab();
    tab2.setText("TAB 2 TEXT");
    tab2.setTabListener(this);
    getSupportActionBar().addTab(tab2);

    ActionBar.Tab tab3 = getSupportActionBar().newTab();
    tab3.setText("TAB 3 TEXT");
    tab3.setTabListener(this);
    getSupportActionBar().addTab(tab3);

    ActionBar.Tab tab4 = getSupportActionBar().newTab();
    tab4.setText("TAB 4 TEXT");
    tab4.setTabListener(this);
    getSupportActionBar().addTab(tab4);
mpwhitt
  • 485
  • 1
  • 5
  • 14

2 Answers2

3

How can I force the tabs to display individually in landscape mode (either in the action bar or below)?

By not using action bar tabs.

The behavior you are seeing is not tied to ActionBarSherlock. ABS is mirroring the behavior of the standard action bar, which will do the same thing. This is by design. It is also stupid, IMHO, but when I filed an issue, I was told that this was working as intended.

If you want your tabs to always be tabs, use any implementation other than action bar tabs, such as a ViewPager with a tabbed indicator.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • its interesting that Google Play app keeps using tabs in landscape but I can't get my own app (with fewer tabs) to do it. There goes the consistency argument. – Karl Oct 29 '13 at 20:28
  • 1
    @Karl: If you are referring to the Play Store, they are not using action bar tabs. The tabs are never in the action bar, in any orientation. Hence, they are quite obviously not action bar tabs. If you use **`uiautomatorviewer`**, you will see that the Play Store uses `ViewPager` with a tabbed indicator. – CommonsWare Oct 30 '13 at 00:42
  • Didn't realize the difference. That's what I wanted all along, thanks! – Karl Oct 30 '13 at 09:52
2

This is the default behavior for the ActionBar.

https://code.google.com/p/android/issues/detail?id=24439

I saw this

https://groups.google.com/forum/#!msg/android-developers/2unF5lKfn64/iKUX7JbbOo4J

After adding tabs to ActionBar call setNavigationMode() for tab navigation mode, e.g.

Tab tabDemo=mTabsAdapter.addTab(bar.newTab().setText("ABC"),.Abc.class, null,"Abc");
bar.setNavigationMode(ActionBar.Navigation_mode_tabs);

It shows tabs in tabbed view mode. I don't know if it works but you can try it.

You can also create a view with tabs instead of using the ActionBar tabs. I believe you have to use ViewPager or something like that.

Trinimon
  • 13,839
  • 9
  • 44
  • 60
Saren Inden
  • 3,450
  • 4
  • 32
  • 45
  • I'm afraid this won't work - tried that two weeks ago and it didn't have an effect. – Trinimon Jun 19 '13 at 20:55
  • Also with a view pager? http://developer.android.com/training/implementing-navigation/lateral.html All the way down to the last item: Use a Title Strip Instead of Tabs – Saren Inden Jun 19 '13 at 20:55
  • 1
    Just checked it again (last time it was a colleague of mine who tried that): seems that it forces in fact the tabs being created in the ActionBar. However, we were looking for getting them below the AB, 'cause space is rare in the AB ;) – Trinimon Jun 20 '13 at 06:17
  • Thanks, this worked just like I needed it to. I was confused at first about the mTabsAdapter but I moved the top line of code down and it worked great. – mpwhitt Jun 20 '13 at 13:19
  • this didn't work for me. Spinner still there in landscape. It's quite buggy that you can still swipe the "tabs" even if there are none. Who swipes a spinner? Also for me at least the spinner doesn't change when I change fragments swiping. – Karl Oct 29 '13 at 20:44