How can I allow horizontal tab navigation (swipe views) with action bar navigation tabs?

烂漫一生 提交于 2020-01-02 09:57:48

问题


How can I allow horizontal tab navigation (swipe views) if I'm using action bar navigation tabs?

Is there anything special I have to do to get this to work with ActionBarSherlock?


回答1:


The code-generated stuff for a "Tabs+Swipe" activity (from BlankActivity in the new activity wizard in Eclipse) has code for this. Basically, your tabs tie into a ViewPager, calling setCurrentItem() to change the page, rather than running their own FragmentTransaction or otherwise affecting the UI. The ViewPager handles the horizontal swiping, and you populate those pages using some form of PagerAdapter (one is code generated for you). See this very related question and answer for more.

Is there anything special I have to do to get this to work with ActionBarSherlock?

Other than standard stuff for using ActionBarSherlock, nothing out of the ordinary should be required. ViewPager is in the Android Support package, which ActionBarSherlock also needs, so you will have that already in your project.

Note, though, that action bar tabs only sometimes show up as tabs. In some screen sizes and orientations, they are automatically converted into a drop-down list (per "list navigation" with the action bar instead of "tab navigation"). If you want to use tabs all of the time, rather than using action bar tabs with ViewPager, use PagerTabStrip (from the Android Support package) or a suitable indicator from ViewPagerIndicator instead.



来源:https://stackoverflow.com/questions/12356238/how-can-i-allow-horizontal-tab-navigation-swipe-views-with-action-bar-navigati

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