Can I embed scrollable tabs inside the action bar?

丶灬走出姿态 提交于 2019-12-12 01:29:36

问题


I'd like to have a layout where screen real estate is important on smaller screens, but I'd like users to be able to swipe between exactly two tabs. On these smaller screened devices, I don't want to waste an entire row with a scrollable tab widget like this:

but fixed tabs offer no indication to users that they can swipe:

Users will typically need to view both tabs to complete the task. Is there any way presently to embed tabs with support for "swipe to switch tabs" inside the main action bar?


回答1:


You can use Tabs with a ViewPager and a FragmentPagerAdapter.

Link them together like so:

 @Override
 public void onPageSelected(int position) {
     getSupportActionBar().setSelectedNavigationItem(position);
 }

 @Override
 public void onTabSelected(Tab tab, FragmentTransaction ft) {
     mViewPager.setCurrentItem(tab.getPosition());
 }

For a more elaborate example check this answer.




回答2:


Not only is it possible to support swiping with standard action bar fixed tabs, it's a design guideline:

Use fixed tabs to support quick changes between two or three app views. Fixed tabs should always allow the user to navigate between the views by swiping left or right on the content area.

Scrollable tabs are different than fixed tabs in that the tab bar itself can be scrolled to see more tabs than will fit on the given display:



来源:https://stackoverflow.com/questions/12432555/can-i-embed-scrollable-tabs-inside-the-action-bar

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