mpwhitt
mpwhitt

Reputation: 495

ActionBarSherlock tabs in landscape orientation

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);

Upvotes: 1

Views: 2064

Answers (2)

Saren Inden
Saren Inden

Reputation: 3660

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.

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1007276

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.

Upvotes: 3

Related Questions