-1

I can't use the method setNavigationMode(ActionBar.NAVIGATION_MODE_TABS) on ActionBar. I don't understand why my Application doesn't run. Isn't it supported by the library?

actionBar.setNavigationMode.(ActionBar.NAVIGATION_MODE_TABS);

Arnaud
  • 7,259
  • 10
  • 50
  • 71
  • Hi try with SlidingTab (for tab) class. Becz setNavigationMode deprected. Refer this link-https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabLayout.java – Sanket990 Sep 08 '15 at 04:16
  • http://stackoverflow.com/questions/27626761/actionbar-setnavigationmode-deprecated – Amol Sawant Sep 08 '15 at 04:40
  • Check: http://stackoverflow.com/questions/26540078/use-tab-with-new-toolbar-appcompat-v7-21/26543020#26543020 – Gabriele Mariotti Sep 08 '15 at 07:13

3 Answers3

0

You should use the design support library TabLayout, https://developer.android.com/reference/android/support/design/widget/TabLayout.html. See http://android-developers.blogspot.no/2015/05/android-design-support-library.html from the section Tabs:

Tabs Switching between different views in your app via tabs is not a new concept to material design and they are equally at home as a top level navigation pattern or for organizing different groupings of content within your app (say, different genres of music).

The Design library’s TabLayout implements both fixed tabs, where the view’s width is divided equally between all of the tabs, as well as scrollable tabs, where the tabs are not a uniform size and can scroll horizontally. Tabs can be added programmatically:

 TabLayout tabLayout = ...;
 tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); 

However, if you are using a ViewPager for horizontal paging between tabs, you can create tabs directly from your PagerAdapter’s getPageTitle() and then connect the two together using setupWithViewPager(). This ensures that tab selection events update the ViewPager and page changes update the selected tab.

Kenneth
  • 3,957
  • 8
  • 39
  • 62
0

Here is mine, you can try it. Hope it's helpful.

First, implements ActionBar.TabListener.

public class MainActivity extends FragmentActivity implements ActionBar.TabListener {}

then, setup in onCreate().

mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(adapter);
    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    mPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.page_margin));

    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    for (int position = 0; position < adapter.getCount(); position++) {
        getActionBar().addTab(getActionBar().newTab()
                .setText(adapter.getPageTitle(position))
                .setTabListener(this));
    }

    getActionBar().setDisplayShowHomeEnabled(false);
    getActionBar().setDisplayShowTitleEnabled(false);

override other,

@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
    mPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}

@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
Tri Ngo Minh
  • 145
  • 1
  • 9
-1

Rather than actionbar navigation mode, I would like to suggest you to use this library. PagerSlidingTabStrip

Because actionbar navigation mode method supports api level 14 and greater than 14 but this library will support from android 2.3 and higher one.

MarmiK
  • 5,639
  • 6
  • 40
  • 49
Jay Poojara
  • 99
  • 1
  • 7