Can I embed scrollable tabs inside the action bar?

2.9k Views Asked by At

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:

scrollable tabs

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

fixed tabs

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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.

enter image description here

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:

enter image description here

0
On

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.