Example usage for android.app ActionBar NAVIGATION_MODE_TABS

List of usage examples for android.app ActionBar NAVIGATION_MODE_TABS

Introduction

In this page you can find the example usage for android.app ActionBar NAVIGATION_MODE_TABS.

Prototype

int NAVIGATION_MODE_TABS

To view the source code for android.app ActionBar NAVIGATION_MODE_TABS.

Click Source Link

Document

Tab navigation mode.

Usage

From source file:vn.com.vng.phim123.HomeActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_activity);

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.//from   w ww. j ava2  s  .  c  o m
    actionBar.setHomeButtonEnabled(true);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.example.kaow.caltest.MainFrag.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.frag_main);//from ww w  .  j  av a 2 s. c om

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    final ActionBar actionBar = getActionBar();
    // Specify that the Home button should show an "Up" caret, indicating that touching the
    // button will take the user one step up in the application's hierarchy.
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });
    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mFoodTitles.length || i < mFoodIcon.length; i++) {
        actionBar.addTab(actionBar.newTab().setIcon(mFoodIcon[i]).setText(mFoodTitles[i]).setTabListener(this));

    }
}

From source file:com.tabs.viewpager.testt.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent./*  ww w  .  j a  v a2s.c o  m*/
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    //        for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
    //            // Create a tab with text corresponding to the page title defined by the adapter.
    //            // Also specify this Activity object, which implements the TabListener interface, as the
    //            // listener for when this tab is selected.
    //            actionBar.addTab(
    //                    actionBar.newTab()
    //                            .setText(mAppSectionsPagerAdapter.getPageTitle(i))
    //                            .setTabListener(this));
    //        }

    //adding tab 1
    actionBar.addTab(actionBar.newTab().setText(R.string.title_orders).setTabListener(this));
    //adding tab 2
    actionBar.addTab(actionBar.newTab().setText(R.string.title_orders).setTabListener(this));
    //adding tab 2
    actionBar.addTab(actionBar.newTab().setText(R.string.title_my_profile).setTabListener(this));
}

From source file:com.vurf.vurfx.view.Place_template.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_place_template);

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    final String TitleNames[] = new String[] { "About", "Main", "Photos" };

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent./*from  w w w .jav  a 2 s  .  c  o  m*/
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });
    // TODO swipy tabs 
    //PagerTitleStrip  mPagerTitleStrip = (PagerTitleStrip) findViewById(R.id.pager_title_strip);

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(actionBar.newTab().setText(TitleNames[i]).setTabListener(this));
    }
    actionBar.hide();
    //mViewPager.setCurrentItem(tab.getPosition())
    mViewPager.setCurrentItem(1);
}

From source file:fr.jcf.pret.activities.ViewPagerSwipingActivity.java

/**
 * Cette mthode construit la bar d'action pour l'activity principale
 *//*from   www .  j av  a2  s. co m*/
private void construireBarAction() {
    // Cration de la listes des fragments que l'on souhaite afficher dans les onglets
    List<Fragment> fragments = new ArrayList<Fragment>();
    fragments.add(new PretsEmpruntsFragment(PretEmpruntContrat.PRET));
    fragments.add(new PretsEmpruntsFragment(PretEmpruntContrat.EMPRUNT));

    // Rcupration de la barre d'action
    actionBar = getActionBar();

    // Instanciation de l'adapter du ViewPager
    mAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragments);

    // On rcupre le ViewPager
    mPager = (ViewPager) findViewById(R.id.pager);

    // On associe l'adapter au pager
    mPager.setAdapter(mAdapter);

    // Lorsqu'un lment du pager change des vnements sont levs
    mPager.setOnPageChangeListener(new OnPageChangeCustomListener(actionBar));

    // La bar de navigation est en mode Onglet ou Tabs
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    Tab tabPrets = actionBar.newTab();
    ActionBarCustomListener tabListenerAlbum = new ActionBarCustomListener(this, 0, mPager);
    tabPrets.setText(R.string.prets_activity);
    tabPrets.setTabListener(tabListenerAlbum);
    actionBar.addTab(tabPrets);

    // On cre chaque Onglet du menu et on l'ajoute  la barre d'action
    Tab tabEmprunts = actionBar.newTab();
    tabEmprunts.setText(R.string.emprunts_activity);
    ActionBarCustomListener tabListenerArtists = new ActionBarCustomListener(this, 1, mPager);
    tabEmprunts.setTabListener(tabListenerArtists);
    actionBar.addTab(tabEmprunts);

}

From source file:com.bonsai.btcreceive.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Turn off "up" navigation since we are the top-level.
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);

    setContentView(R.layout.activity_main);

    mAdapter = new MyAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);//from ww  w .j  a  v  a 2s.  c o m

    // Specify that tabs should be displayed in the action bar.
    final android.app.ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create a tab listener that is called when the user changes tabs.
    TabListener tabListener = new TabListener() {
        @Override
        public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {
        }

        @Override
        public void onTabSelected(Tab tab, android.app.FragmentTransaction ft) {
            // show the given tab
            int position = tab.getPosition();
            manageKeyboard(position);
            mPager.setCurrentItem(position);
        }

        @Override
        public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {
        }
    };

    // Add tabs to the view pager.
    actionBar.addTab(
            actionBar.newTab().setText(mRes.getString(R.string.tab_receive)).setTabListener(tabListener));
    actionBar.addTab(
            actionBar.newTab().setText(mRes.getString(R.string.tab_transactions)).setTabListener(tabListener));
    actionBar.addTab(
            actionBar.newTab().setText(mRes.getString(R.string.tab_account)).setTabListener(tabListener));

    // Listen for swiped changes to the view pager.
    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between pages, select the
            // corresponding tab.
            manageKeyboard(position);
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    mLogger.info("MainActivity created");
}

From source file:com.mac.SafeWalk.WelcomeActivity.java

/**
 * Called when the activity is first created.
 *//*from ww w .  j  a va 2s. c om*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.welcome_screen);
    // Create adapter
    collectionPagerAdapter = new CollectionPagerAdapter(getSupportFragmentManager());

    // Set up action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.hide();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical parent.
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager
    // Attache the adapter and implement listener in order to respond when user swipes between sections.
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(collectionPagerAdapter);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // Select the corresponding tab when user swipes
            actionBar.setSelectedNavigationItem(position);
            ImageView dot1 = (ImageView) findViewById(R.id.sliding_dot1);
            ImageView dot2 = (ImageView) findViewById(R.id.sliding_dot2);
            switch (position) {
            case 0:
                animate(dot1);
                break;
            case 1:
                animate(dot2);
                break;
            case 2:
                break;
            }
        }
    });
    // For each of the sections, add tab to the action bar.
    for (int i = 0; i < collectionPagerAdapter.getCount(); i++) {
        // Create tabs
        actionBar.addTab(actionBar.newTab().setTabListener(this));
    }
    Settings.getSettings().setContext(this);
}

From source file:com.networksaremadeofstring.anonionooid.RelayDetailsSwipe.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_relay_details_swipe);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mContext = this;
    if (null == lc)
        lc = new LocalCache(mContext);

    lc.open();//from  ww  w  .jav  a 2  s  . c  om
    isFavourite = lc.isAFavourite(getIntent().getStringExtra(Ooo.ARG_ITEM_ID));
    lc.close();

    // Show the Up button in the action bar.
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setIcon(R.drawable.ab_icon);

    try {
        //fingerprint =
        actionBar.setSubtitle(getIntent().getStringExtra(Ooo.ARG_ITEM_ID));

    } catch (Exception e) {
        e.printStackTrace();
    }

    if (savedInstanceState == null) {
        // Create the detail fragment and add it to the activity
        // using a fragment transaction.
        arguments = new Bundle();
        arguments.putString(Ooo.ARG_ITEM_ID, getIntent().getStringExtra(Ooo.ARG_ITEM_ID));

        /*RelayDetailFragment fragment = new RelayDetailFragment();
        fragment.setArguments(arguments);
        getFragmentManager().beginTransaction()
            .add(R.id.relay_detail_container, fragment)
            .commit();*/
    }

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.lifestats.MainActivity.java

/**
 * onCreate: Setup Tab structure and Action Bar.
 *
 * @param savedInstanceState saved instance state.
 *//*from  ww w  . j  a  v a 2 s  .com*/
@Override
public void onCreate(Bundle savedInstanceState) {

    /**
     * Routine create view.
     */
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    /**
     * Setup the ViewPager and its Adapter.
     */
    PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mPager.setOffscreenPageLimit(0);

    /**
     * Change selected ActionBar title when swipe left or right.
     */
    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @SuppressWarnings("ConstantConditions")
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    /**
     * Setup ActionBar displaying the Tab titles.
     */
    final ActionBar actionBar = getActionBar();
    assert actionBar != null;
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    /**
     * Setup TabListener to display the correct tab content.
     */
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            mPager.setCurrentItem(tab.getPosition());
        }

        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
        }

        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
        }
    };

    /**
     * Add the actual Tabs to the page.
     * 1. Record activity tab.
     * 2. Show activity tab.
     */
    ActionBar.Tab recordTab = actionBar.newTab();
    recordTab.setText(R.string.recordActivities);
    recordTab.setTabListener(tabListener);
    actionBar.addTab(recordTab);

    ActionBar.Tab showTab = actionBar.newTab();
    showTab.setText(R.string.showActivities);
    showTab.setTabListener(tabListener);
    actionBar.addTab(showTab);

}

From source file:it.personal.keyring.SetupActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setup);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override// w ww  .ja  va2s .  c om
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}