Search code examples
javaandroidactionbarsherlock

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

Solution

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