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.bignerdranch.android.fragmentbasics.NewsReaderActivity.java

/** Sets up Action Bar (if present).
 *
 * @param showTabs whether to show tabs (if false, will show list).
 * @param selTab the selected tab or list item.
 *///ww  w . j  a va 2s. co m
public void setUpActionBar(boolean showTabs, int selTab) {
    if (Build.VERSION.SDK_INT < 11) {
        // No action bar for you!
        // But do not despair. In this case the layout includes a bar across the
        // top that looks and feels like an action bar, but is made up of regular views.
        return;
    }

    android.app.ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);

    // Set up a CompatActionBarNavHandler to deliver us the Action Bar nagivation events
    CompatActionBarNavHandler handler = new CompatActionBarNavHandler(this);
    if (showTabs) {
        actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_TABS);
        int i;
        for (i = 0; i < CATEGORIES.length; i++) {
            actionBar.addTab(actionBar.newTab().setText(CATEGORIES[i]).setTabListener(handler));
        }
        actionBar.setSelectedNavigationItem(selTab);
    } else {
        actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_LIST);
        SpinnerAdapter adap = new ArrayAdapter<String>(this, R.layout.actionbar_list_item, CATEGORIES);
        actionBar.setListNavigationCallbacks(adap, handler);
    }

    // Show logo instead of icon+title.
    actionBar.setDisplayUseLogoEnabled(true);
}

From source file:com.ibm.msg.android.ConnectionDetails.java

/**
 * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
 */// w ww .  j a  v  a 2 s .co m
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    clientHandle = getIntent().getStringExtra("handle");

    setContentView(R.layout.activity_connection_details);
    // Create the adapter that will return a fragment for each of the pages
    sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

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

    // add the sectionsPagerAdapter
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(sectionsPagerAdapter);

    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // select the tab that represents the current page
            actionBar.setSelectedNavigationItem(position);

        }
    });

    // Create the tabs for the screen
    for (int i = 0; i < sectionsPagerAdapter.getCount(); i++) {
        ActionBar.Tab tab = actionBar.newTab();
        tab.setText(sectionsPagerAdapter.getPageTitle(i));
        tab.setTabListener(this);
        actionBar.addTab(tab);
    }

    connection = Connections.getInstance(this).getConnection(clientHandle);
    changeListener = new ChangeListener();
    connection.registerChangeListener(changeListener);
}

From source file:com.whitespider.impact.ble.sensortag.ViewPagerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(mResourceFragmentPager);

    // Set up the action bar
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ImageView view = (ImageView) findViewById(android.R.id.home);
    //view.setPadding(10, 0, 20, 10);

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(mResourceIdPager);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//  w ww .  ja  va  2  s  .  c  o  m
        public void onPageSelected(int n) {
            // Log.d(TAG, "onPageSelected: " + n);
            actionBar.setSelectedNavigationItem(n);
        }
    });
    // Create the adapter that will return a fragment for each section
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager.setAdapter(mSectionsPagerAdapter);

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

    this.busyDialog = new Dialog(this);
    this.busyDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    ;
    this.busyDialog.setContentView(R.layout.frame_progress);
    this.progressBarTextView = (TextView) this.busyDialog.findViewById(R.id.progressTextView);
}

From source file:com.example.adbird.MenuTabActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_menu);//from ww  w . j ava 2 s  .  c om
    mContext = this.getApplicationContext();

    SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
    String lang = prefs.getString("lang", null);
    Locale locale = new Locale(lang);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
    SpannableString s = new SpannableString(mContext.getResources().getString(R.string.ads_title));
    s.setSpan(new TypefaceSpan(this, "GothaProReg.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setTitle(s);
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    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);

            SpannableString s = new SpannableString(mAppSectionsPagerAdapter.getPageTitle(position));
            s.setSpan(new TypefaceSpan(getApplicationContext(), "GothaProReg.otf"), 0, s.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            actionBar.setTitle(s);
        }
    });

    // 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().setIcon(mAppSectionsPagerAdapter.getPageIcon(i)).setTabListener(this));

    }

}

From source file:com.schedule.ScheduleActivity.java

/**
 * Sets up Action Bar (if present)./*w ww.  java2  s.  c o  m*/
 * 
 * @param showTabs
 *            whether to show tabs (if false, will show list).
 * @param selTab
 *            the selected tab or list item.
 */
public void setUpActionBar(boolean showTabs, int selTab) {
    if (Build.VERSION.SDK_INT < 11) {
        // No action bar for you!
        // But do not despair. In this case the layout includes a bar across
        // the
        // top that looks and feels like an action bar, but is made up of
        // regular views.
        return;
    }

    android.app.ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);

    // Set up a CompatActionBarNavHandler to deliver us the Action Bar
    // nagivation events
    CompatActionBarNavHandler handler = new CompatActionBarNavHandler(this);
    if (showTabs) {
        actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_TABS);
        int i;
        for (i = 0; i < MENUS.length; i++) {
            actionBar.addTab(actionBar.newTab().setText(MENUS[i]).setTabListener(handler));
        }
        actionBar.setSelectedNavigationItem(selTab);
    } else {
        actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_LIST);
        SpinnerAdapter adap = new ArrayAdapter<String>(this, R.layout.actionbar_list_item, MENUS);
        actionBar.setListNavigationCallbacks(adap, handler);
    }

    // Show logo instead of icon+title.
    actionBar.setDisplayUseLogoEnabled(true);
}

From source file:com.indragie.cmput301as1.ExpenseClaimListActivity.java

/**
 * Set up fragments to display expense claim data.
 *//*w ww .  j a va2 s .co m*/
private void setupFragments() {
    User user = userManager.getActiveUser();
    Session session = new Session(this, user);
    Session.setSharedSession(session);

    pagerAdapter = new ExpenseClaimPagerAdapter(this, getSupportFragmentManager(), user);
    pager.setAdapter(pagerAdapter);

    // From http://developer.android.com/training/implementing-navigation/lateral.html
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            pager.setCurrentItem(tab.getPosition());
        }

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

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

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

    Tab ownedTab = actionBar.newTab().setText(R.string.tab_owned).setTabListener(tabListener);
    Tab reviewalTab = actionBar.newTab().setText(R.string.tab_reviewal).setTabListener(tabListener);

    actionBar.addTab(ownedTab);
    actionBar.addTab(reviewalTab);
}

From source file:de.ncoder.sensorsystem.android.app.MainActivity.java

private void onCreateTabs() {
    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    if (actionBar == null) {
        return;/*w  w w .  j a  v a2 s  .c  om*/
    }
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return tab fragments
    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

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

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

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

From source file:com.android.browser.ComboViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setResult(RESULT_CANCELED);/*  w  w  w .  j a  v a2  s. c  o m*/
    Bundle extras = getIntent().getExtras();
    Bundle args = extras.getBundle(EXTRA_COMBO_ARGS);
    String svStr = extras.getString(EXTRA_INITIAL_VIEW, null);
    ComboViews startingView = svStr != null ? ComboViews.valueOf(svStr) : ComboViews.Bookmarks;
    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.tab_view);
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    if (BrowserActivity.isTablet(this)) {
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_USE_LOGO);
        bar.setHomeButtonEnabled(true);
    } else {
        bar.setDisplayOptions(0);
    }

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_bookmarks), BrowserBookmarksPage.class, args);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_history), BrowserHistoryPage.class, args);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_TAB, 0));
    } else {
        switch (startingView) {
        case Bookmarks:
            mViewPager.setCurrentItem(0);
            break;
        case History:
            mViewPager.setCurrentItem(1);
            break;
        case Snapshots:
            mViewPager.setCurrentItem(2);
            break;
        }
    }
}

From source file:com.plnyyanks.frcnotebook.activities.ViewEvent.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(PreferenceHandler.getTheme());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_event);

    activity = this;

    if (event == null) {
        Intent intent = new Intent(this, StartActivity.class);
        startActivity(intent);//  w  w w  .j a  v  a 2s  .  c  om
        return;
    }

    ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setTitle(event.getEventName());
    bar.setSubtitle("#" + key);
    bar.setDisplayHomeAsUpEnabled(true);

    //tab for team list
    ActionBar.Tab teamListTab = bar.newTab();
    teamListTab.setText("Teams Attending");
    teamListTab.setTabListener(this);
    bar.addTab(teamListTab);

    //tab for match schedule
    ActionBar.Tab scheduleTab = bar.newTab();
    scheduleTab.setText("Match Schedule");
    scheduleTab.setTabListener(this);
    bar.addTab(scheduleTab);

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

From source file:com.piusvelte.cloudset.android.CloudSetMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext());
    setContentView(R.layout.activity_main);
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(sectionsPagerAdapter);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*  www . j a  v  a  2  s.com*/
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

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

    SharedPreferences sp = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE);
    account = sp.getString(PREFERENCE_ACCOUNT_NAME, null);
    deviceId = sp.getLong(PREFERENCE_DEVICE_ID, INVALID_DEVICE_ID);
    setCurrentTab();

    // create the loader for registration, deregistration, and loading
    // devices
    LoaderManager loaderManager = getSupportLoaderManager();
    loaderManager.initLoader(0, null, this);

    if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_LOADER_IDS)) {
        loaderIds = savedInstanceState.getIntegerArrayList(EXTRA_LOADER_IDS);
    } else {
        loaderIds = new ArrayList<Integer>();
    }

    for (int i = 0, s = loaderIds.size(); i < s; i++) {
        // reconnect to additional loaders for deregistering additional
        // devices
        loaderManager.initLoader(loaderIds.get(i), null, this);
    }
}