ActionBarSherlock tabs in landscape orientation

时间秒杀一切 提交于 2019-12-23 03:30:06

问题


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

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/17200952/actionbarsherlock-tabs-in-landscape-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!