Example usage for android.app ActionBar setSelectedNavigationItem

List of usage examples for android.app ActionBar setSelectedNavigationItem

Introduction

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

Prototype

@Deprecated
public abstract void setSelectedNavigationItem(int position);

Source Link

Document

Set the selected navigation item in list or tabbed navigation modes.

Usage

From source file:com.prolificcoder.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    final ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from w  w w  .j  av a2 s  .com
        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 < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.hybris.mobile.activity.UIComponentsActivity.java

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

    setContentView(R.layout.activity_ui_components);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    Fragment[] frags = { new UIComponents1Fragment(), new UIComponents2Fragment() };
    FragmentPagerAdapter adapter = new TabsAdapter(getFragmentManager(), frags);
    mViewPager.setAdapter(adapter);//from   w w  w .  j a  v a2 s.  c o  m
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    MyTabListener tabListener = new MyTabListener(mViewPager, actionBar);
    Tab tab = actionBar.newTab().setText(R.string.tab_ui_components1).setTabListener(tabListener);
    actionBar.addTab(tab);

    tab = actionBar.newTab().setText(R.string.tab_ui_components2).setTabListener(tabListener);
    actionBar.addTab(tab);
    actionBar.setSelectedNavigationItem(0);
}

From source file:net.cherryzhang.sekuhara.LoginAndRegistration.LoginAndRegistrationActivity.java

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

    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    Parse.initialize(this, "TsVbzF7jXzY1C0o86V2xxAxgSxvy4jmbyykOabPl",
            "VzamwWm4WswbDFxrxos2oSerQ2Av4RM6J5mNnNgr");

    final ActionBar actionBar = getActionBar();
    actionBar.hide();//w ww .  j  a  v  a2s.co m
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);

    ViewPager.SimpleOnPageChangeListener mPageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    };

    pageIndicator = (CirclePageIndicator) findViewById(R.id.CPI_pageIndicator);
    pageIndicator.setViewPager(mViewPager);
    pageIndicator.setOnPageChangeListener(mPageChangeListener);
    pageIndicator.setCurrentItem(0);

    //TODO: make circle page indicator look better
    final float density = getResources().getDisplayMetrics().density;
    pageIndicator.setRadius(6 * density);
    pageIndicator.setPageColor(0xFFFFCCFF);
    pageIndicator.setFillColor(0xFFFF6699);
    pageIndicator.setStrokeColor(0xFF000000);
    pageIndicator.setStrokeWidth(1);

    // 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.bionx.res.about.InformationCenter.java

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

    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());
    final ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*from w ww  .  jav  a 2  s  .  c  o m*/
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.android.photos.GalleryActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mMultiChoiceManager = new MultiChoiceManager(this);
    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.viewpager);/*from   w ww  .  j a v  a  2 s .c  o  m*/
    setContentView(mViewPager);

    ActionBar ab = getActionBar();
    ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ab.setDisplayShowHomeEnabled(false);
    ab.setDisplayShowTitleEnabled(false);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(ab.newTab().setText(R.string.tab_photos), PhotoSetFragment.class, null);
    mTabsAdapter.addTab(ab.newTab().setText(R.string.tab_albums), AlbumSetFragment.class, null);

    if (savedInstanceState != null) {
        ab.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}

From source file:org.floens.chan.ui.activity.BoardActivity.java

/**
 * Sets the navigator to appropriately and calls startLoadingBoard
 *
 * @param board//from   www. j  a v  a  2 s  . c  om
 */
private void loadBoard(String board) {
    boardLoadable = new Loadable(board);

    int index = getBoardIndexNavigator(boardLoadable.board);
    if (index >= 0) {
        ActionBar actionBar = getActionBar();
        setActionBarListMode();

        if (actionBar.getSelectedNavigationIndex() != index) {
            actionBar.setSelectedNavigationItem(index);
        } else {
            startLoadingBoard(boardLoadable);
        }
    } else {
        startLoadingBoard(boardLoadable);
    }
}

From source file:org.kanbansalad.scanner.client.android.ScanActivity.java

private void enableSwipeToMoveBetweenTabs(final ActionBar actionBar) {
    // 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.
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from w  w  w .  jav a 2  s.c  om
        public void onPageSelected(int position) {
            // TODO Move to presenter?
            actionBar.setSelectedNavigationItem(position);
        }
    });
}

From source file:com.eftimoff.viewpagertransformers.MainActivity.java

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

    int selectedPage = 0;
    if (savedInstanceState != null) {
        mSelectedItem = savedInstanceState.getInt(KEY_SELECTED_CLASS);
        selectedPage = savedInstanceState.getInt(KEY_SELECTED_PAGE);
    }//  w ww. ja  v  a  2 s. com

    final ArrayAdapter<TransformerItem> actionBarAdapter = new ArrayAdapter<TransformerItem>(
            getApplicationContext(), android.R.layout.simple_list_item_1, android.R.id.text1,
            TRANSFORM_CLASSES);

    final ActionBar actionBar = getActionBar();
    actionBar.setListNavigationCallbacks(actionBarAdapter, this);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);

    setContentView(R.layout.activity_main);

    mAdapter = new PageAdapter(getSupportFragmentManager());

    mPager = (ViewPager) findViewById(R.id.container);
    mPager.setAdapter(mAdapter);
    mPager.setCurrentItem(selectedPage);

    actionBar.setSelectedNavigationItem(mSelectedItem);
}

From source file:com.matze5800.paupdater.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set View/*from   w  ww  .j  a va 2 s .c o m*/
    setContentView(R.layout.activity_main);
    context = this;
    // Get SharedPreferences
    prefs = PreferenceManager.getDefaultSharedPreferences(context);

    // ActionBar / PagerAdapter
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getFragmentManager());

    final ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);
    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) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    // Finishes Activity if device is not supported
    device = Functions.detectDevice(context);
    if (device.equals("unsupported")) {
        finish();
    }
}

From source file:pack_generic.Act_NSPS.java

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

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);//from  w w  w  .  j  a va2 s . c  o  m
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText("Frag_Page"), Frag_Page.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Frag_List_Contacts"), Frag_List_Contacts.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Frag_Tabs"), Frag_Tabs.class, null);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}