Example usage for android.app ActionBar NAVIGATION_MODE_TABS

List of usage examples for android.app ActionBar NAVIGATION_MODE_TABS

Introduction

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

Prototype

int NAVIGATION_MODE_TABS

To view the source code for android.app ActionBar NAVIGATION_MODE_TABS.

Click Source Link

Document

Tab navigation mode.

Usage

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

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

    activity = this;

    ActionBar bar = getActionBar();//w  w w .ja  va  2  s .  c om
    bar.setTitle(teamNumber != -1 ? "Team " + teamNumber : "All Data");

    //tab for team overview
    ActionBar.Tab teamOverviewTab = bar.newTab();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    teamOverviewTab.setText("All Notes");
    teamOverviewTab.setTag("all");
    teamOverviewTab.setTabListener(this);
    bar.addTab(teamOverviewTab);
    bar.setDisplayHomeAsUpEnabled(true);

    //add an actionbar tab for every event the team is competing at
    ArrayList<String> events;
    if (teamNumber == -1) {
        events = StartActivity.db.getAllEventKeys();
    } else {
        Team team = StartActivity.db.getTeam(teamKey);
        events = team.getTeamEvents();
    }
    for (String eventKey : events) {
        Log.d(Constants.LOG_TAG, "Making AB Tab for " + eventKey);
        Event event = StartActivity.db.getEvent(eventKey);
        if (event == null)
            continue;
        ActionBar.Tab eventTab = bar.newTab();
        eventTab.setTag(event.getEventKey());
        eventTab.setText(event.getShortName());
        eventTab.setTabListener(this);
        bar.addTab(eventTab);
    }

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

}

From source file:ca.psiphon.ploggy.ActivityMain.java

@Override
protected 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.
    mAppTabsPagerAdapter = new AppTabsPagerAdapter(getSupportFragmentManager());

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

    // 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);
    mViewPager.setAdapter(mAppTabsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/* www .  j a v  a2 s  .c  o m*/
        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);
        }
    });

    actionBar.addTab(actionBar.newTab().setText(R.string.title_self_status_fragment).setTabListener(this));

    actionBar.addTab(actionBar.newTab().setText(R.string.title_friend_list_fragment).setTabListener(this));

    actionBar.addTab(actionBar.newTab().setText(R.string.title_message_list_fragment).setTabListener(this));
    mMessageListTabIndex = 2;

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

From source file:com.linkedin.android.eventsapp.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    pager = new ViewPager(this);
    pager.setId(R.id.pager);/* ww w .ja va  2  s . c o  m*/
    pager.setOffscreenPageLimit(5);
    setContentView(pager);

    final ActionBar bar = getActionBar();
    View viewActionBar = getLayoutInflater().inflate(R.layout.layout_action_bar, null);

    TextView textviewTitle = (TextView) viewActionBar.findViewById(R.id.actionbar_textview);
    ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
    textviewTitle.setText("UPCOMING EVENTS");
    bar.setCustomView(viewActionBar, params);
    bar.setDisplayShowCustomEnabled(true);
    bar.setDisplayShowTitleEnabled(false);
    bar.setIcon(new ColorDrawable(Color.TRANSPARENT));
    bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F15153")));

    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mEventTabsAdapter = new com.linkedin.android.eventsapp.EventTabsAdapter(this, pager);
    SimpleDateFormat ft = new SimpleDateFormat("E dd MMM");
    ArrayList<Event> events = EventsManager.getInstance(this).getEvents();
    for (Event event : events) {
        String eventDay = ft.format(new Date(event.getEventDate()));
        mEventTabsAdapter.addTab(bar.newTab().setText(eventDay), EventFragment.class, event);
    }
}

From source file:com.normalexception.neobd.NeobdActivity.java

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

    appContext = this;

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

    // For each of the sections in the app, add a tab to the action bar.
    actionBar.addTab(actionBar.newTab().setText(R.string.title_section_welcome)
            .setTabListener(new TabListener(new WelcomeTab())));
    actionBar.addTab(actionBar.newTab().setText(R.string.title_section_obd2)
            .setTabListener(new TabListener(new OBDTab())));
    actionBar.addTab(actionBar.newTab().setText(R.string.title_section_dtc)
            .setTabListener(new TabListener(new DTCTab())));

    // Initialize the database
    neod = NEODatabase.getInstance();//from ww w .j  av a 2 s  .co  m
}

From source file:com.example.android.OurApp.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*www.  ja v a2  s. c  o  m*/

    // 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);
    FragmentPagerAdapter pagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        // ?position?Fragment
        @Override
        public Fragment getItem(int position) {
            Fragment fragment = new DummyFragment();
            Bundle args = new Bundle();
            args.putInt(DummyFragment.ARG_SECTION_NUMBER, position + 1);
            fragment.setArguments(args);
            return fragment;
        }

        // iAdapterFragment
        @Override
        public int getCount() {
            return 3;
        }

        // ?Fragment
        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
            case 0:
                return "";
            case 1:
                return "";
            case 2:
                return "";
            }
            return null;
        }
    };

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

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

    mViewPager.setAdapter(pagerAdapter);
    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);
        }
    });

}

From source file:org.messic.android.activities.BaseActivity.java

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

    // 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 activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

    // 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/*ww w.j  av a 2 s.  c  o  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++) {
        // 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));
    }
}

From source file:com.android.quickreturnlistview.sample_app.MainActivity.java

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

    PagerAdapter adapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) {
        @Override/* ww  w  .jav  a  2s  .  c o m*/
        public Fragment getItem(int position) {
            switch (position) {
            case 0:
                return DefaultFragment.newInstance(false);
            case 1:
                return DefaultFragment.newInstance(true);
            }
            return null;
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
            case 0:
                return getString(R.string.default_fragment);
            case 1:
                return getString(R.string.animation_fragment);
            }
            return null;
        }
    };

    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(adapter);
    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    for (int position = 0; position < adapter.getCount(); position++) {
        getActionBar()
                .addTab(getActionBar().newTab().setText(adapter.getPageTitle(position)).setTabListener(this));
    }

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

From source file:org.digitalcampus.oppia.activity.AboutActivity.java

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

    setContentView(R.layout.activity_about);
    actionBar = getActionBar();//w  w w.j  av  a 2 s. com
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    viewPager = (ViewPager) findViewById(R.id.activity_about_pager);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    Bundle bundle = this.getIntent().getExtras();
    if (bundle != null) {
        currentTab = (Integer) bundle.getSerializable(AboutActivity.TAB_ACTIVE);
    }
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().addFlags(Window.FEATURE_ACTION_BAR);

    setResult(RESULT_CANCELED);/*from ww  w .j  a  v a2s . 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);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_snapshots), BrowserSnapshotPage.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.intel.internal.telephony.mdmclitest.activities.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.main);
    // Create the adapter that will return a fragment for each
    // primary sections of the app. like 'Modem Management BASIC OPS'
    operationTitleAdapter = new OperationTitleAdapter(super.getSupportFragmentManager(), this);

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

    // Set up the ViewPager with the sections adapter.
    this.viewPager = (ViewPager) super.findViewById(R.id.pager);

    if (this.viewPager == null) {
        return;/*from   w w  w  .  ja  v  a  2  s  . c  o  m*/
    }

    String[] tabInfo = new String[0];

    if (isDSDA) {
        tabInfo = getResources().getStringArray(R.array.tab_name);
    } else {
        viewPager.removeView(findViewById(R.id.pagertab));
    }

    pageComponentList = new ArrayList<PageComponent>();

    // Now we have two Action Bars: OperationTitle & SectionsPager
    // Delete the Page change listener of OperationTitle,
    // the swaping of SectionsPager only will be enabled.

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < operationTitleAdapter.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.
        CharSequence pageTitleName = operationTitleAdapter.getPageTitle(i);

        pageComponentList.add(new PageComponent(pageTitleName,
                new SectionsPagerAdapter(super.getSupportFragmentManager(), tabInfo)));

        actionBar.addTab(actionBar.newTab().setText(pageTitleName).setTabListener(this));
    }

    PageComponent firstPage = pageComponentList.get(0);
    if ((null != firstPage)) {
        this.viewPager.setAdapter(firstPage.getFragmentPagerAdapter());
    }
}