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:se.dxapps.generic.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final ActionBar actionBar = getActionBar();
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    mTitle = mDrawerTitle = getTitle();/*from  w  ww . j a  va  2s  .co  m*/
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    //        if (savedInstanceState == null) {
    //            selectItem(0);
    //        }

    //ViewPager stuff. 

    // 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.fn.reunion.app.ui.base.AppBaseActivity.java

private void initPager() {

    // Initialization

    viewPager = (ViewPager) findViewById(R.id.pager);
    actionBar = getActionBar();/*from   ww  w  .  jav a2s.  com*/
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

    viewPager.setAdapter(mAdapter);
    actionBar.setHomeButtonEnabled(true);

    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    }

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Adding Tabs
    for (String tab_name : tabs) {
        actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this));
    }
    actionBar.getTabAt(0).setIcon(R.drawable.rss_32);
    actionBar.getTabAt(1).setIcon(R.drawable.chat_32);
    // actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_background_textured_theme_fn_chat));

    /**
     * on swiping the viewpager make respective tab selected
     * */
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // on changing the page
            // make respected tab selected
            actionBar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });

}

From source file:com.codebutler.farebot.activity.CardInfoActivity.java

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

    setContentView(R.layout.activity_card_info);
    final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    mTabsAdapter = new TabPagerAdapter(this, viewPager);

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(R.string.loading);

    new AsyncTask<Void, Void, Void>() {
        private Exception mException;
        public boolean mSpeakBalanceEnabled;

        @Override/*from  w  ww.ja v  a 2 s . com*/
        protected Void doInBackground(Void... voids) {
            try {
                Uri uri = getIntent().getData();
                Cursor cursor = getContentResolver().query(uri, null, null, null, null);
                startManagingCursor(cursor);
                cursor.moveToFirst();

                String data = cursor.getString(cursor.getColumnIndex(CardsTableColumns.DATA));

                mCard = Card.fromXml(FareBotApplication.getInstance().getSerializer(), data);
                mTransitData = mCard.parseTransitData();

                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(CardInfoActivity.this);
                mSpeakBalanceEnabled = prefs.getBoolean("pref_key_speak_balance", false);
            } catch (Exception ex) {
                mException = ex;
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            findViewById(R.id.loading).setVisibility(View.GONE);
            findViewById(R.id.pager).setVisibility(View.VISIBLE);

            if (mException != null) {
                if (mCard == null) {
                    Utils.showErrorAndFinish(CardInfoActivity.this, mException);
                } else {
                    Log.e("CardInfoActivity", "Error parsing transit data", mException);
                    showAdvancedInfo(mException);
                    finish();
                }
                return;
            }

            if (mTransitData == null) {
                showAdvancedInfo(new UnsupportedCardException());
                finish();
                return;
            }

            String titleSerial = (mTransitData.getSerialNumber() != null) ? mTransitData.getSerialNumber()
                    : Utils.getHexString(mCard.getTagId(), "");
            actionBar.setTitle(mTransitData.getCardName() + " " + titleSerial);

            Bundle args = new Bundle();
            args.putString(AdvancedCardInfoActivity.EXTRA_CARD,
                    mCard.toXml(FareBotApplication.getInstance().getSerializer()));
            args.putParcelable(EXTRA_TRANSIT_DATA, mTransitData);

            if (mTransitData instanceof UnauthorizedClassicTransitData) {
                mTabsAdapter.addTab(actionBar.newTab(), UnauthorizedCardFragment.class, args);
                return;
            }

            if (mTransitData.getBalanceString() != null) {
                mTabsAdapter.addTab(actionBar.newTab().setText(R.string.balance), CardBalanceFragment.class,
                        args);
            }

            if (mTransitData.getTrips() != null || mTransitData.getRefills() != null) {
                mTabsAdapter.addTab(actionBar.newTab().setText(R.string.history), CardTripsFragment.class,
                        args);
            }

            if (mTransitData.getSubscriptions() != null) {
                mTabsAdapter.addTab(actionBar.newTab().setText(R.string.subscriptions),
                        CardSubscriptionsFragment.class, args);
            }

            if (mTransitData.getInfo() != null) {
                mTabsAdapter.addTab(actionBar.newTab().setText(R.string.info), CardInfoFragment.class, args);
            }

            if (mTabsAdapter.getCount() > 1) {
                actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            }

            if (mTransitData.hasUnknownStations()) {
                findViewById(R.id.need_stations).setVisibility(View.VISIBLE);
            }

            boolean speakBalanceRequested = getIntent().getBooleanExtra(SPEAK_BALANCE_EXTRA, false);
            if (mSpeakBalanceEnabled && speakBalanceRequested) {
                mTTS = new TextToSpeech(CardInfoActivity.this, mTTSInitListener);
            }

            if (savedInstanceState != null) {
                viewPager.setCurrentItem(savedInstanceState.getInt(KEY_SELECTED_TAB, 0));
            }
        }
    }.execute();
}

From source file:com.landenlabs.all_devtool.TabPagerAdapter.java

public TabPagerAdapter(FragmentManager fm, ViewPager viewPager, ActionBar actionBar) {
    super(fm);/*from w w  w  . j a  va 2s.c o  m*/

    m_viewPager = viewPager;
    m_actionBar = actionBar;
    m_viewPager.setAdapter(this);

    // Keep all fragments cached.
    //   m_viewPager.setOffscreenPageLimit(this.getCount());

    if (m_actionBar != null) {
        m_actionBar.setHomeButtonEnabled(false);
        m_actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        // Adding Tabs
        for (int tabIdx = 0; tabIdx < this.getCount(); tabIdx++) {
            m_actionBar.addTab(m_actionBar.newTab().setText(this.getTabName(tabIdx)).setTabListener(this));
        }
    }

    /*
     * On swiping the viewpager sets respective tab selected.
     */
    if (m_actionBar != null) {
        m_viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                if (m_actionBar != null) {
                    m_actionBar.setSelectedNavigationItem(position);
                }
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
            }
        });

        m_actionBar.setSelectedNavigationItem(0);
    }
}

From source file:com.betterAlarm.deskclock.DeskClock.java

private void createTabs(int selectedIndex) {
    mActionBar = getActionBar();/*from  www . j  a  v a  2  s . co  m*/

    if (mActionBar != null) {
        mActionBar.setDisplayOptions(0);
        mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        mAlarmTab = mActionBar.newTab();
        mAlarmTab.setIcon(R.drawable.ic_alarm_animation);
        mAlarmTab.setContentDescription(R.string.menu_alarm);
        mTabsAdapter.addTab(mAlarmTab, AlarmClockFragment.class, ALARM_TAB_INDEX);

        mClockTab = mActionBar.newTab();
        mClockTab.setIcon(R.drawable.ic_clock_animation);
        mClockTab.setContentDescription(R.string.menu_clock);
        mTabsAdapter.addTab(mClockTab, ClockFragment.class, CLOCK_TAB_INDEX);

        mTimerTab = mActionBar.newTab();
        mTimerTab.setIcon(R.drawable.ic_timer_animation);
        mTimerTab.setContentDescription(R.string.menu_timer);
        mTabsAdapter.addTab(mTimerTab, TimerFragment.class, TIMER_TAB_INDEX);

        mStopwatchTab = mActionBar.newTab();
        mStopwatchTab.setIcon(R.drawable.ic_stopwatch_animation);
        mStopwatchTab.setContentDescription(R.string.menu_stopwatch);
        mTabsAdapter.addTab(mStopwatchTab, StopwatchFragment.class, STOPWATCH_TAB_INDEX);

        mActionBar.setSelectedNavigationItem(selectedIndex);
        mTabsAdapter.notifySelectedPage(selectedIndex);
    }
}

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

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

    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());
    final ActionBar actionBar = getActionBar();

    actionBar.setHomeButtonEnabled(false);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from ww w  . j  ava  2s.co  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);
        }
    });

    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        if (i == 0) {
            actionBar.addTab(actionBar.newTab().setText("Run Payment").setTabListener(this));
        } else if (i == 1) {
            actionBar.addTab(actionBar.newTab().setText("Store Token").setTabListener(this));
        } else if (i == 2) {
            actionBar.addTab(actionBar.newTab().setText("Swipe Card").setTabListener(this));
        } else {
            actionBar.addTab(
                    actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
        }
    }

}

From source file:com.ezevents.android.app.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    cont = this;//from ww w .j ava 2 s. c o m
    intent = getIntent();

    setContentView(R.layout.activity_main);

    mTitle = mDrawerTitle = getTitle();
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    //mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        @Override
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // 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.
    //            
    //        }

    String sec1 = "My Events";
    String sec2 = "Popular Events";
    String sec3 = "Notifications";

    actionBar.addTab(actionBar.newTab().setText(sec1).setTabListener(this));

    actionBar.addTab(actionBar.newTab().setText(sec2).setTabListener(this));

    actionBar.addTab(actionBar.newTab().setText(sec3).setTabListener(this));

}

From source file:give_me_coins.dashboard.MainScreen.java

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

    setContentView(R.layout.main_screen);

    //create file for shared preference
    sharedPref = getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);

    API_key_saved = sharedPref.getString(getString(R.string.saved_api_key), "");
    if (sharedPref.getBoolean(getString(R.string.show_ltc), true)) {
        coin_select = 1;//from  w  w w.j  av  a2 s  .co m
    } else if (sharedPref.getBoolean(getString(R.string.show_btc), true)) {
        coin_select = 2;
    } else if (sharedPref.getBoolean(getString(R.string.show_ftc), true)) {
        coin_select = 3;
    }

    // Start service to receive data
    //if(mService==null) mService= new GMCService(this,mHandler);
    if (mPoolService == null)
        mPoolService = new GMCPoolService(mHandler);

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

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

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

    // Specify that tabs should be displayed in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // For each of the sections in the app, add a tab to the action bar.
    // 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("Settings")
            //.setIcon(R.drawable.settings)
            .setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText("Summary")
            // .setIcon(R.drawable.dashboard)
            .setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText("Pool")
            //.setIcon(R.drawable.news)
            .setTabListener(this));

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    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);
        }
    });

    actionBar.setBackgroundDrawable(new ColorDrawable(R.color.menu_background));

    // mViewPager.setCurrentItem(0);
    if (API_key_saved != null && !API_key_saved.equals("")) {
        if (!"No api key found".equals(API_key_saved)) {
            startService();
            // change to summary tab if api key is set and everything
            mViewPager.setCurrentItem(1);
        }
    }

}

From source file:net.theneophyte.sunstone.app.deskclock.DeskClock.java

private void createTabs(int selectedIndex) {
    mActionBar = getActionBar();/* ww w  .j ava  2 s . co  m*/

    if (mActionBar != null) {
        mActionBar.setDisplayOptions(0);
        mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        mAlarmTab = mActionBar.newTab();
        mAlarmTab.setIcon(R.drawable.alarm_tab);
        mAlarmTab.setContentDescription(R.string.menu_alarm);
        mTabsAdapter.addTab(mAlarmTab, AlarmClockFragment.class, ALARM_TAB_INDEX);

        //            mClockTab = mActionBar.newTab();
        //            mClockTab.setIcon(R.drawable.clock_tab);
        //            mClockTab.setContentDescription(R.string.menu_clock);
        //            mTabsAdapter.addTab(mClockTab, ClockFragment.class, CLOCK_TAB_INDEX);
        //
        //            mTimerTab = mActionBar.newTab();
        //            mTimerTab.setIcon(R.drawable.timer_tab);
        //            mTimerTab.setContentDescription(R.string.menu_timer);
        //            mTabsAdapter.addTab(mTimerTab, TimerFragment.class, TIMER_TAB_INDEX);
        //
        //            mStopwatchTab = mActionBar.newTab();
        //            mStopwatchTab.setIcon(R.drawable.stopwatch_tab);
        //            mStopwatchTab.setContentDescription(R.string.menu_stopwatch);
        //            mTabsAdapter.addTab(mStopwatchTab, StopwatchFragment.class, STOPWATCH_TAB_INDEX);

        mActionBar.setSelectedNavigationItem(selectedIndex);
        mTabsAdapter.notifySelectedPage(selectedIndex);
    }
}

From source file:com.actionbarsherlock.sample.styled.MainActivityICS.java

private void showTabsNav() {
    ActionBar ab = getActionBar();//from  w  w  w  . j  ava 2  s. c  o m
    if (ab.getNavigationMode() != ActionBar.NAVIGATION_MODE_TABS) {
        ab.setDisplayShowTitleEnabled(true);
        ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    }
}