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.cyanogenmod.settings.SlideSettings.java

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.settings_view);
    mContext = getApplicationContext();/*from   w  ww.  ja v a  2 s .co m*/
    mAdapter = new SettingsAdapter(getFragmentManager());
    mActionBar = getActionBar();
    mPager = (ViewPager) findViewById(R.id.settings_pager);
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mActionBar.setDisplayShowTitleEnabled(true);

    for (String entry : mAdapter.getTabs()) {
        ActionBar.Tab tab = mActionBar.newTab();
        tab.setTabListener(new TabListener() {
            @Override
            public void onTabReselected(Tab tab, FragmentTransaction ft) {
            }

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

            @Override
            public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            }
        });
        tab.setText(entry);
        mActionBar.addTab(tab);
    }

    mPager.setAdapter(mAdapter);
    mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int idx) {
            mActionBar.selectTab(mActionBar.getTabAt(idx));
        }

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

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

From source file:com.project.binbinfu.the_city.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.

    //mHotPagerAdapter = new HotPagerAdapter(getSupportFragmentManager());
    fragmentmanager = 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 .j ava 2  s  . co  m*/
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs 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.

    actionBar.addTab(actionBar.newTab().setText(R.string.title_section1).setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText(R.string.title_section2).setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText(R.string.title_section3).setTabListener(this));
}

From source file:com.codingrhemes.steamsalesmobile.GameSaleActivity.java

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

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

    if (savedInstanceState == null) {
        // Setting up bundle to keep values
        Bundle mostPopGames = new Bundle();
        mostPopGames.putBoolean("isMostPopular", true);
        dailyDealFragment = new DealOfTheDayFragment();
        gamesFragment = new GamesFragment();
        mostPopularFragment = new MostPopularGamesFragment();
        // set them to the fragment
        mostPopularFragment.setArguments(mostPopGames);
    }//from   w  w  w  .ja  va 2s  .c o  m

    // 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
        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.example.adbird.MenuTabActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_menu);//  ww  w .j a v a  2  s .c om
    mContext = this.getApplicationContext();

    SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
    String lang = prefs.getString("lang", null);
    Locale locale = new Locale(lang);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
    SpannableString s = new SpannableString(mContext.getResources().getString(R.string.ads_title));
    s.setSpan(new TypefaceSpan(this, "GothaProReg.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setTitle(s);
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);

            SpannableString s = new SpannableString(mAppSectionsPagerAdapter.getPageTitle(position));
            s.setSpan(new TypefaceSpan(getApplicationContext(), "GothaProReg.otf"), 0, s.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            actionBar.setTitle(s);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setIcon(mAppSectionsPagerAdapter.getPageIcon(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 .  j  av a  2 s  .c  om

    // 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:dk.bearware.gui.AudioCodecActivity.java

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

    audiocodec = Utils.getAudioCodec(this.getIntent());

    int tab_index = 0;
    switch (audiocodec.nCodec) {
    case Codec.OPUS_CODEC:
        opuscodec = audiocodec.opus;//from  w  w  w.  j av a 2 s . c o  m
        tab_index = TAB_OPUS;
        break;
    case Codec.SPEEX_CODEC:
        speexcodec = audiocodec.speex;
        tab_index = TAB_SPEEX;
        break;
    case Codec.SPEEX_VBR_CODEC:
        speexvbrcodec = audiocodec.speex_vbr;
        tab_index = TAB_SPEEXVBR;
        break;
    case Codec.NO_CODEC:
        tab_index = TAB_NOAUDIO;
        break;
    }

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

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

    mViewPager.setCurrentItem(tab_index);
}

From source file:br.com.GUI.perfil.HomeAluno.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home_aluno);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    //Starta O servio
    Intent i = new Intent(this, WorkUpService.class);
    startService(i);/*  w  w  w.java 2 s . c o  m*/

    pref = getApplicationContext().getSharedPreferences("MyPref", 0);
    editor = pref.edit();
    b = new Banco(this, null, null, 0);

    // Initilization

    Log.i("usuario", pref.getString("usuario", null));
    Log.i("tipo", pref.getString("tipo", null));
    viewPager = (ViewPager) findViewById(R.id.pagerHomeAluno);
    viewPager.setOffscreenPageLimit(5);
    actionBar = getActionBar();
    mAdapter = new TabsPagerAdapterHomeAluno(getSupportFragmentManager());

    viewPager.setAdapter(mAdapter);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Adding Tabs
    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.icon_personal_trainer_tab).setTabListener(this));

    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.icon_acompanhamento_tab).setTabListener(this));

    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.icon_agenda_tab).setTabListener(this));

    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.icon_perfil_tab).setTabListener(this));
    /**
     * 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.lemontruck.thermo.MainActivity.java

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

    // Find the widget id from the intent. 
    Intent intent = getIntent();//from  w w  w .  ja va 2  s . com
    Bundle extras = intent.getExtras();
    if (extras != null) {
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    }

    // If they gave us an intent without the widget id, just bail.
    if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
        Log.w(LOG, "Invalid App Id");
        finish();
    }
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

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

    // 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);
    //actionBar.setDisplayShowTitleEnabled(false);

    // Set the result to CANCELED.  This will cause the widget host to cancel
    // out of the widget placement if they press the back button.
    setResult(RESULT_CANCELED);

    // 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.dvdprime.mobile.android.ui.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();

    // 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/*from  w ww  .j  a  v  a 2 s  . com*/
        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);
            EasyTracker.getTracker().sendView(AppSectionsPagerAdapter.tabEngTitles[position]);
            LOGD("Tracker", AppSectionsPagerAdapter.tabEngTitles[position]);
            // Save position value in preference
            PrefUtil.getInstance().setInt(PrefKeys.LAST_TAB_POSITION, 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));
    }

    // Google Analytics
    EasyTracker.getInstance().setContext(this);
    EasyTracker.getTracker().sendView("Main");
    LOGD("Tracker", "Main");

    // Set Last Tab
    lastPosition = PrefUtil.getInstance().getInt(PrefKeys.LAST_TAB_POSITION, 0);
    actionBar.setSelectedNavigationItem(lastPosition);

    //  .
    if (PrefUtil.getInstance().getString(PrefKeys.ACCOUNT_ID, null) != null) {
        JsonObjectRequest filterReq = new JsonObjectRequest(
                StringUtil.format(Config.MOBILE_DP_COUNT,
                        PrefUtil.getInstance().getString(PrefKeys.ACCOUNT_ID, null)),
                null, createJsonReqSuccessListener(), createJsonReqErrorListener());
        filterReq.setTag(TAG);
        DpApp.getRequestQueue().add(filterReq);
    }

    //   ?
    if (SystemUtil.getVersionName(this).equals("1.0")
            && PrefUtil.getInstance().getBoolean(PrefKeys.VERSION_1_0, true)) {
        String msg = new StringBuffer().append("[1.0 ]\n\n").append(
                "-?   \n  ? ?? ?  ? ?? /?.\n\n")
                .append("-   \n  ?  ?    ?. ?  ? ?.")
                .toString();
        new AlertDialog.Builder(this).setTitle(getString(R.string.alert_dialog_version)).setMessage(msg)
                .setCancelable(false)
                .setPositiveButton(getString(R.string.alert_dialog_ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        PrefUtil.getInstance().setBoolean(PrefKeys.VERSION_1_0, false);
                        dialog.dismiss();
                    }
                }).create().show();
    }
}

From source file:com.hardcopy.arduinonavi.MainActivity.java

/*****************************************************
 *    Overrided methods/*from  w ww  . jav a  2s. co m*/
 ******************************************************/

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

    //----- System, Context
    mContext = this; //.getApplicationContext();
    mActivityHandler = new ActivityHandler();
    AppSettings.initializeAppSettings(mContext);

    setContentView(R.layout.activity_main);

    // 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 primary sections of the app.
    mFragmentManager = getSupportFragmentManager();
    mSectionsPagerAdapter = new FragmentAdapter(mFragmentManager, mContext, this, mActivityHandler);

    // 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.
    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.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    // Setup views

    mNaviInfo = (TextView) findViewById(R.id.status_navi_info);
    mNaviInfo.setText(getResources().getString(R.string.title_destination) + ": ");
    mNaviMode = (Button) findViewById(R.id.btn_mode);
    mNaviMode.setOnClickListener(this);
    showUnitTypeButton();

    mImageBT = (ImageView) findViewById(R.id.status_title);
    mImageBT.setImageDrawable(getResources().getDrawable(android.R.drawable.presence_invisible));
    mTextStatus = (TextView) findViewById(R.id.status_text);
    mTextStatus.setText(getResources().getString(R.string.bt_state_init));

    // Do data initialization after service started and binded
    doStartService();
}