Example usage for android.support.v4.app ActionBar addTab

List of usage examples for android.support.v4.app ActionBar addTab

Introduction

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

Prototype

public abstract void addTab(ActionBar.Tab tab);

Source Link

Document

Add a tab for use in tabbed navigation mode.

Usage

From source file:com.actionbarsherlock.sample.hcgallery.MainActivity.java

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

    if (savedInstanceState != null && savedInstanceState.getInt("theme", -1) != -1) {
        mThemeId = savedInstanceState.getInt("theme");
        this.setTheme(mThemeId);
    }//from   www  .j  av  a 2s.  com

    setContentView(R.layout.main);

    Directory.initializeDirectory();

    ActionBar bar = getSupportActionBar();

    int i;
    for (i = 0; i < Directory.getCategoryCount(); i++) {
        bar.addTab(bar.newTab().setText(Directory.getCategory(i).getName()).setTabListener(this));
    }

    mActionBarView = getLayoutInflater().inflate(R.layout.action_bar_custom, null);

    bar.setCustomView(mActionBarView);
    bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO);
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayShowHomeEnabled(true);

    // If category is not saved to the savedInstanceState,
    // 0 is returned by default.
    if (savedInstanceState != null) {
        int category = savedInstanceState.getInt("category");
        bar.selectTab(bar.getTabAt(category));
    }
}

From source file:com.actionbarsherlock.sample.styledactionbar.MainActivity.java

/** Called when the activity is first created. */
@Override//from w  w  w.j  av  a 2s .c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final ActionBar ab = getSupportActionBar();

    // set defaults for logo & home up
    ab.setDisplayHomeAsUpEnabled(showHomeUp);
    ab.setDisplayUseLogoEnabled(useLogo);

    // set up tabs nav
    for (int i = 1; i < 4; i++) {
        ab.addTab(ab.newTab().setText("Tab " + i).setTabListener(this));
    }

    // set up list nav
    ab.setListNavigationCallbacks(ArrayAdapter.createFromResource(this, R.array.sections,
            android.R.layout.simple_spinner_dropdown_item), new OnNavigationListener() {
                public boolean onNavigationItemSelected(int itemPosition, long itemId) {
                    // FIXME add proper implementation
                    rotateLeftFrag();
                    return false;
                }
            });

    // default to tab navigation
    showTabsNav();

    // create a couple of simple fragments as placeholders
    final int MARGIN = 16;
    leftFrag = new RoundedColourFragment(getResources().getColor(R.color.android_green), 1f, MARGIN, MARGIN / 2,
            MARGIN, MARGIN);
    rightFrag = new RoundedColourFragment(getResources().getColor(R.color.honeycombish_blue), 2f, MARGIN / 2,
            MARGIN, MARGIN, MARGIN);

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.add(R.id.root, leftFrag);
    ft.add(R.id.root, rightFrag);
    ft.commit();
}