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.example.bijesh.mycollege10.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();
    //action bar color
    actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));
    //tab color// w w w .ja v  a 2 s .co m
    //   actionBar.setStackedBackgroundDrawable(getResources().getDrawable(R.drawable.bluewall));
    //tab background color
    //        actionBar.setStackedBackgroundDrawable(getResources().getDrawable(
    // R.drawable.greenwall));

    // 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, 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.univ.helsinki.app.MainActivity.java

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

    if (FeedResource.getInstance().getSharedPrefs().getBoolean(Constant.SHARED_PREFS_KEY_ISFIRST_LAUNCH,
            false)) {/*w w w .j ava  2  s . c  om*/

        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        getActionBar().hide();

        hideTitle();
    }

    setContentView(R.layout.activity_main);

    splashLayout = (ViewGroup) findViewById(R.id.splashLayout);

    if (FeedResource.getInstance().getSharedPrefs().getBoolean(Constant.SHARED_PREFS_KEY_ISFIRST_LAUNCH,
            false)) {
        // record the fact that the app has been started at least once
        FeedResource.getInstance().getSharedPrefs().edit()
                .putBoolean(Constant.SHARED_PREFS_KEY_ISFIRST_LAUNCH, false).commit();

        final ViewGroup splashLayout = (ViewGroup) findViewById(R.id.splashLayout);

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                activateSplashScreen(splashLayout);
            }
        }, Constant.SPLASH_SCREEN_TIME_OUT);

    } else {
        splashLayout.setVisibility(View.GONE);
    }

    FeedResource.getInstance().inti(this);

    // 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();

    mSensorFeedAdapter = new SensorFeedAdapter(this);

    // 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, 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);
            switch (position) {
            case 0: {
                // on focus when first fragment
                //Toast.makeText(getApplicationContext(), "onPageSelected :" + position, Toast.LENGTH_SHORT).show();

                List<SensorFeed> mtempAllowedSensorFeedList = new ArrayList<SensorFeed>();
                // update the list over here.. to avoid empty shell
                for (SensorFeed sensor : FeedResource.getInstance().getSensorFeedList()) {

                    boolean isChecked = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
                            .getBoolean(sensor.getSensorKey(), false);

                    if (isChecked)
                        mtempAllowedSensorFeedList.add(sensor);
                }
                // update the list with new created list
                mSensorFeedAdapter.setFeedList(mtempAllowedSensorFeedList);

            }
                break;
            }// switch ends
        }
    });

    // 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.reliqartz.firsttipcalc.gui.MainActivity.java

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

    loadPreferences();/*from  w  w w .  ja  va  2  s .co  m*/

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

    // initialize fragments
    if (savedInstanceState == null) {
        mCalculator = new CalcFragment();
        mSplitter = new SplitterFragment();
    } else {
        mCalculator = (CalcFragment) getSupportFragmentManager().getFragment(savedInstanceState,
                CalcFragment.TAG);
        mSplitter = (SplitterFragment) getSupportFragmentManager().getFragment(savedInstanceState,
                SplitterFragment.TAG);
    }

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the application.
    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
        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));
    }

    // setup fonts
    applyFonts();
}

From source file:org.ounl.lifelonglearninghub.fcube.navigate.SwipeFragmentActivity.java

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

    // 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.//w w  w. java 2s  .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));
    }

}

From source file:it.durip_app.SensorPlot.java

/** Called when the activity is first created. */
@Override//ww  w. ja  v  a  2 s .  com
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sensors);
    managerSensor = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
    textCharge = (TextView) findViewById(R.id.textvalueConsumption);
    // 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.
    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);
        }
    });

    managerSensor = (SensorManager) this.getSystemService(SENSOR_SERVICE);
    List<Sensor> list = managerSensor.getSensorList(Sensor.TYPE_ALL);
    for (Sensor sensor : list) {
        System.out.println("NAME " + sensor.getName());
    }

    // For each of the sections in the app, add a tab to the action bar.
    for (int ii = 1; ii <= mAppSectionsPagerAdapter.getCount(); ii++) {
        // 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(ii)).setTabListener(this));

    }
    // Show the Up button in the action bar.        

    //        System.out.println("OnCreate \n");

}

From source file:com.stj.fileexplorer.FileExplorerTabActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    // add begin by xugaoming@20140317, don't need to restore
    // fragments automaticaly if killed by system for memory,
    // it will mess up the logic
    savedInstanceState = null;//ww w .  j a  v  a2  s. c  o  m
    // add end

    super.onCreate(savedInstanceState);
    StorageHelper.getInstance(this);
    setContentView(R.layout.fragment_pager);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setOffscreenPageLimit(DEFAULT_OFFSCREEN_PAGES);

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

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    //        mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_category),
    //                FileCategoryActivity.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_sd), FileViewActivity.class, null);

    FileViewActivity fileViewActivity = ((FileViewActivity) getFragment(Util.SDCARD_TAB_INDEX));
    fileViewActivity.registBottomBtnPressListener(this);

    /*mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_remote),
        ServerControlActivity.class, null);*/
    int selectedItem = PreferenceManager.getDefaultSharedPreferences(this).getInt(INSTANCESTATE_TAB,
            Util.CATEGORY_TAB_INDEX);
    if (Intent.ACTION_PICK.equals(getIntent().getAction())) {
        selectedItem = Util.SDCARD_TAB_INDEX;
    }
    //add begin by xugaoming@20140517, add function to locate
    //to a directory
    Intent intent = getIntent();
    if (intent != null && intent.getStringExtra("goto_dir") != null) {
        selectedItem = Util.SDCARD_TAB_INDEX;
    }
    //add end
    bar.setSelectedNavigationItem(0);
}

From source file:com.shafiq.mytwittle.view.HomeActivity.java

private boolean configureListNavigation() {

    if (mSpinnerAdapter == null) {
        return false;
    }//ww  w. j ava  2  s.  co m

    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener);

    int accountIndex = 0;
    AccountDescriptor currentAccount = getApp().getCurrentAccount();
    if (currentAccount != null) {
        String testScreenName = "@" + currentAccount.getScreenName()
                + (currentAccount.getSocialNetType() == SocialNetConstant.Type.Appdotnet ? " (App.net)"
                        : " (Twitter)");
        for (int i = 0; i < mAdapterStrings.length; i++) {
            if (testScreenName.toLowerCase().equals(mAdapterStrings[i].toLowerCase())) {
                accountIndex = i;
                break;
            }
        }
    }
    actionBar.setSelectedNavigationItem(accountIndex);
    actionBar.setDisplayHomeAsUpEnabled(false);
    return true;
}

From source file:edu.gatech.architourists.VAActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_va);

    ArchitectureDataSource ds = new ArchitectureDataSource(this);
    ds.open();//from w  w w .  j a  v  a  2 s .  c om
    allArchNames = ds.getSiteList();
    architects = ds.getArchitectList();
    stylesite = ds.getStyleList();
    periodsite = ds.getPeriodList();
    ds.close();

    architects = makeAlphabetical(architects);
    stylesite = makeAlphabetical(stylesite);
    periodsite = makeAlphabetical(periodsite);

    // 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.
    // 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(tabTitles[i]).setTabListener(this));
    }

}

From source file:es.farfuteam.vncpp.controller.ActivityTabs.java

/**
 * @param savedInstanceState//from  w w w  .j a va  2  s  . c o m
 * @brief This is the onCreate method
 * @details The onCreate method adds an actionBar to the activity with two tabs (recent and favorites).
 * It also load the preferences file into the prefs attribute and sets the rememeberExit attribute.
 */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_host);

    final ActionBar actionBar = getActionBar();

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME);

    final String recents = getString(R.string.recents);
    final String favorites = getString(R.string.favoritesTab);

    // add tabs
    Tab tab1 = actionBar.newTab().setText(recents)
            .setTabListener(new TabListener<ListFragmentTab>(this, "tab1", ListFragmentTab.class));
    actionBar.addTab(tab1);

    Tab tab2 = actionBar.newTab().setText(favorites)
            .setTabListener(new TabListener<ListFragmentTabFav>(this, "tab2", ListFragmentTabFav.class));

    actionBar.addTab(tab2);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    //accedemos a fichero preferencias
    (Configuration.getInstance()).setPrefs(getSharedPreferences("PreferencesFile", Context.MODE_PRIVATE));

    (Configuration.getInstance()).readPrefs();

    // Orientation Change Occurred
    if (savedInstanceState != null) {
        int currentTabIndex = savedInstanceState.getInt("tab_index");
        actionBar.setSelectedNavigationItem(currentTabIndex);
    }

    //nombre en la activity bar
    final String title = getString(R.string.connections);
    setTitle(title);

}

From source file:com.tweetlanes.android.view.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    //StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().penaltyDialog().build());
    //StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
    //StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());

    super.onCreate(savedInstanceState);

    AccountDescriptor account = getApp().getCurrentAccount();

    // Attempt at fixing a crash found in HomeActivity
    if (account == null) {
        Toast.makeText(getApplicationContext(), "No cached account found, restarting",
                Constant.DEFAULT_TOAST_DISPLAY_TIME).show();
        restartApp();/*from   w w w. j a va2 s .  co  m*/
        return;
    }

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayUseLogoEnabled(true);
    actionBar.setTitle(null);
    actionBar.setDisplayShowTitleEnabled(false);

    ArrayList<String> adapterList = new ArrayList<String>();
    ArrayList<AccountDescriptor> accounts = getApp().getAccounts();
    for (int i = 0; i < accounts.size(); i++) {
        AccountDescriptor acc = accounts.get(i);
        adapterList.add("@" + acc.getScreenName());
    }
    adapterList.add(getString(R.string.add_account));
    mAdapterStrings = adapterList.toArray(new String[adapterList.size()]);

    mSpinnerAdapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item,
            mAdapterStrings);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener);
    actionBar.setSelectedNavigationItem(0);

    onCreateNavigationListener();
    configureListNavigation();

    mViewSwitcher = (ViewSwitcher) findViewById(R.id.rootViewSwitcher);
    updateViewVisibility();

    onCreateHandleIntents();

    account.setDisplayedLaneDefinitionsDirty(false);

    configureNotificationService();
}