Example usage for android.app ActionBar addTab

List of usage examples for android.app ActionBar addTab

Introduction

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

Prototype

@Deprecated
public abstract void addTab(Tab tab);

Source Link

Document

Add a tab for use in tabbed navigation mode.

Usage

From source file:com.gieseckedevrient.android.pcscdroid.MainActivity.java

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

    appContext = getApplicationContext();

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

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

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*  w  ww. j  a  v  a  2s.  c o  m*/
        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.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);/*  ww w .ja  va  2s.  co 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.lifestats.MainActivity.java

/**
 * onCreate: Setup Tab structure and Action Bar.
 *
 * @param savedInstanceState saved instance state.
 *///from w  w  w  .  j a va 2s  .  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:org.aakashlabs.arthashastra.Novice_Activity.java

/** Called when the activity is first created. */
@Override//from w w w.j  av a 2  s  .  c o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_novice);

    //ActionBar gets initiated
    ActionBar actionbar = getActionBar();
    //Tell the ActionBar we want to use Tabs.
    actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    //initiating both tabs and set text to it.
    ActionBar.Tab Part1NTab = actionbar.newTab().setText("Part 1");
    ActionBar.Tab Part2NTab = actionbar.newTab().setText("Part 2");
    ActionBar.Tab Part3NTab = actionbar.newTab().setText("Part 3");

    //create the two fragments we want to use for display content
    // these are two objects of the fragment classes (yet to be made)   
    Fragment Part1NFragment = new Part1N();
    Fragment Part2NFragment = new Part2N();
    Fragment Part3NFragment = new Part3N();

    //set the Tab listener. Now we can listen for clicks.
    Part1NTab.setTabListener(new MyTabsListener(Part1NFragment));
    Part2NTab.setTabListener(new MyTabsListener(Part2NFragment));
    Part3NTab.setTabListener(new MyTabsListener(Part3NFragment));

    //add the two tabs to the action bar
    actionbar.addTab(Part1NTab);
    actionbar.addTab(Part2NTab);
    actionbar.addTab(Part3NTab);

}

From source file:ru.lizaalert.hotline.ui.MainActivity.java

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

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

    mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager());

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

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*  w  ww .j a  v a2s. c  o m*/
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
            if (position == 1) {
                if (getCurrentFocus() != null) {
                    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                            INPUT_METHOD_SERVICE);
                    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
                }
            }

        }
    });

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {

        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.facebook.reflection.SwipeActivity.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());

    Intent intent = getIntent();//  w w  w.java2s .com
    result = intent.getStringArrayListExtra("result");
    // 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);

    // 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);
    mAppSectionsPagerAdapter.setResult(result);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int 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:name.gumartinm.weather.information.activity.MainTabsActivity.java

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

    this.mPager = (ViewPager) this.findViewById(R.id.pager);
    this.mPager.setAdapter(new TabsAdapter(this.getSupportFragmentManager()));

    this.mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from   w  ww  . j ava  2 s.c o  m
        public void onPageSelected(final int position) {
            MainTabsActivity.this.getActionBar().setSelectedNavigationItem(position);
        }
    });

    final ActionBar actionBar = this.getActionBar();

    PreferenceManager.setDefaultValues(this, R.xml.weather_preferences, false);

    // Specify that tabs should be displayed in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Create a tab listener that is called when the user changes tabs.
    final ActionBar.TabListener tabListener = new ActionBar.TabListener() {

        @Override
        public void onTabSelected(final Tab tab, final FragmentTransaction ft) {
            MainTabsActivity.this.mPager.setCurrentItem(tab.getPosition());

        }

        @Override
        public void onTabUnselected(final Tab tab, final FragmentTransaction ft) {

        }

        @Override
        public void onTabReselected(final Tab tab, final FragmentTransaction ft) {

        }

    };

    actionBar.addTab(actionBar.newTab().setText(this.getString(R.string.text_tab_currently))
            .setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(this.getString(R.string.text_tab_five_days_forecast))
            .setTabListener(tabListener));
}

From source file:org.aakashlabs.arthashastra.Advanced_Activity.java

/** Called when the activity is first created. */
@Override/*from  ww  w.  ja v  a  2 s. c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_advanced);

    //ActionBar gets initiated
    ActionBar actionbar = getActionBar();
    //Tell the ActionBar we want to use Tabs.
    actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    //initiating both tabs and set text to it.
    ActionBar.Tab Part1ATab = actionbar.newTab().setText("Part 1");
    ActionBar.Tab Part2ATab = actionbar.newTab().setText("Part 2");
    //  ActionBar.Tab Part3ATab = actionbar.newTab().setText("Part 3");

    //create the two fragments we want to use for display content
    // these are two objects of the fragment classes (yet to be made)   
    Fragment Part1AFragment = new Part1A();
    Fragment Part2AFragment = new Part2A();
    // Fragment Part3AFragment=  new Part3A();

    //set the Tab listener. Now we can listen for clicks.
    Part1ATab.setTabListener(new MyTabsListener3(Part1AFragment));
    Part2ATab.setTabListener(new MyTabsListener3(Part2AFragment));
    //      Part3ATab.setTabListener(new MyTabsListener3(Part3AFragment));

    //add the two tabs to the action bar
    actionbar.addTab(Part1ATab);
    actionbar.addTab(Part2ATab);
    // actionbar.addTab(Part3ATab);

}

From source file:com.androiduipatterns.smashingandroidui.examples.tabs.TabsExampleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tabs_example);
    // 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 action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // 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./*from  ww  w  .ja  v  a  2s . co m*/
    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
        // listener for when this tab is selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.jauker.badgeview.example.TabActivity.java

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

    // 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 w  w.j  a  v a  2s  .co  m*/
        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++) {
        Tab tab = actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this);
        actionBar.addTab(tab);
    }
}