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.example.administrator.myapplication2._2_exercise._2_End._2_EndMain.java

/*****************************************************
 *    Overrided methods//from   w  w  w. j a v a 2  s. c  o  m
 ******************************************************/

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

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

    setContentView(R.layout._2_end_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));
    }

}

From source file:ch.bfh.instacircle.NetworkActiveActivity.java

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

    // 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);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from   w  ww  . jav  a2 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++) {
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    // Handle the change of the Wifi configuration
    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    adhoc = new AdhocWifiManager(wifi);
    wifiapmanager = new WifiAPManager();
    registerReceiver(wifiReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));

    // Is NFC available on this device?
    nfcAvailable = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC);

    // only set up the NFC stuff if NFC is also available
    if (nfcAvailable) {
        nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (nfcAdapter.isEnabled()) {

            // Setting up a pending intent that is invoked when an NFC tag
            // is tapped on the back
            pendingIntent = PendingIntent.getActivity(this, 0,
                    new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

            nfcIntentFilter = new IntentFilter();
            nfcIntentFilter.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
            nfcIntentFilter.addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
            intentFiltersArray = new IntentFilter[] { nfcIntentFilter };
        } else {
            nfcAvailable = false;
        }
    }
}

From source file:com.example.office.ui.Office365DemoActivity.java

/**
 * Initializes activity UI elements.//from  ww  w  .j  a v a 2  s  . c o m
 */
private void initUi() {
    if (!mIsInitialized) {
        setContentView(R.layout.main_activity);

        mTitle = mDrawerTitle = getTitle();

        // Setting up Action Bar and Tabs.
        ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setLogo(R.drawable.ic_action_mail);

        Tab tab = actionBar.newTab().setText(UI.Screen.CONTACTS.getName(this))
                .setTag(UI.Screen.CONTACTS.getName(this)).setTabListener(new TabListener<ContactsFragment>(this,
                        UI.Screen.CONTACTS.getName(this), ContactsFragment.class));
        actionBar.addTab(tab);

        tab = actionBar.newTab().setText(UI.Screen.MAILBOX.getName(this))
                .setTag(UI.Screen.MAILBOX.getName(this)).setTabListener(new TabListener<DraftsFragment>(this,
                        UI.Screen.MAILBOX.getName(this), DraftsFragment.class));
        actionBar.addTab(tab, true);

        tab = actionBar.newTab().setText(UI.Screen.CALENDAR.getName(this))
                .setTag(UI.Screen.CALENDAR.getName(this)).setTabListener(new TabListener<CalendarFragment>(this,
                        UI.Screen.CALENDAR.getName(this), CalendarFragment.class));
        actionBar.addTab(tab);

        // Setting up sliding drawer.
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);

        SlidingDrawerAdapter drawerAdapter = new SlidingDrawerAdapter(OfficeApplication.getContext(),
                R.layout.drawer_list_item, R.layout.drawer_delimiter);
        mDrawerList.setAdapter(drawerAdapter);

        mDrawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                try {
                    Screen[] drawerScreens = ScreenGroup.DRAWER.getMembers().toArray(new Screen[0]);
                    Screen currentScreen = DEFAULT_SCREEN;

                    // use id instead of position here because some positions used by delimiters, id contains real index of clicked item
                    if (drawerScreens != null && drawerScreens.length - 1 >= id) {
                        currentScreen = drawerScreens[(int) id];
                    }
                    switchScreen(currentScreen);
                } catch (Exception e) {
                    Logger.logApplicationException(e, getClass().getSimpleName() + "onItemClick(): Error.");
                }
            }
        });

        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, /* drawer navigation image replacing '<' */
                R.string.drawer_open, R.string.drawer_close) {
            public void onDrawerClosed(View view) {
                getActionBar().setTitle(mTitle);
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(mDrawerTitle);
                invalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        mIsInitialized = true;
    }

    if (mSavedFragmentTag == null) {
        switchScreen(DEFAULT_SCREEN);
    } else {
        // This is not used mostly as we're going back to this activity when it
        // is at the top of the back stack. So (as it does have 'singleTop' in parameters) it is
        // simply restored and onNewIntent() is called instead of onCreate().
        // So savedInstanceState will usually be null. This is added to anticipate other future use cases.
        switchScreen(Screen.getByTag(mSavedFragmentTag, this));
    }
}

From source file:com.example.kaow.caltest.UserInfo.java

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

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

    final ActionBar actionBar = getActionBar();
    // Specify that the Home button should show an "Up" caret, indicating that touching the
    // button will take the user one step up in the application's hierarchy.
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override// w w  w. j a  v  a2  s  .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 each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < uInfoTitles.length; i++) {
        actionBar.addTab(actionBar.newTab().setText(uInfoTitles[i]).setTabListener(this));

    }
}

From source file:de.WyLight.WyLight.WiflyControlActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (null != savedInstanceState) {
        mARGB = savedInstanceState.getInt(STATE_KEY_COLOR, 0xffffffff);
        Color.colorToHSV(mARGB, mHSV);
    }//  w  ww.  j  ava2  s . com

    setContentView(R.layout.view_pager);

    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(false);

    final ViewPager pager = (ViewPager) findViewById(R.id.pager);
    final WiflyPagerAdapter adapter = new WiflyPagerAdapter(getFragmentManager());
    pager.setAdapter(adapter);
    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        public void onPageScrolled(int arg0, float arg1, int arg2) {
            /* not implemented */
        }

        public void onPageScrollStateChanged(int arg0) {
            /* not implemented */
        }

        public void onPageSelected(int arg0) {
            getActionBar().setSelectedNavigationItem(arg0);
            mFragments[arg0].onShow(mMenu);
        }
    });

    TabListener listener = new TabListener(pager);
    for (int i = 0; i < pager.getAdapter().getCount(); ++i) {
        Tab tab = actionBar.newTab().setIcon(mFragments[i].getIcon()).setTabListener(listener);
        actionBar.addTab(tab);
    }

    Intent i = getIntent();
    mRemote = (Endpoint) i.getSerializableExtra(EXTRA_ENDPOINT);
}

From source file:com.xortech.sender.SenderMain.java

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

    // REMOVE THE TITLE FROM THE ACTIONBAR
    getActionBar().setDisplayShowTitleEnabled(false);

    preferences = PreferenceManager.getDefaultSharedPreferences(this);

    mapType = preferences.getString("mapType", GMAPS);

    // CHECK FOR "DON'T KEEP ACTIVITIES" IN DEVELOPER OPTIONS
    boolean checkDeveloper = isAlwaysFinishActivitiesOptionEnabled();
    if (checkDeveloper) {
        showDeveloperOptionsScreen();/*  w w w .  jav  a  2s.  com*/
    }

    /*
     * IF GOOGLE MAPS IS SELECTED AS THE DEFAULT, THEN CHECK TO
     * SEE IF THE USER HAS THE CORRECT VERSION OF GOOGLE PLAY SERVICES
     */
    if (mapType.equals(GMAPS)) {
        // GET GOOGLE PLAY STATUS
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

        // CHECK IF GOOGLE PLAY SERVICE IS AVAILABLE 
        try {
            if (status != ConnectionResult.SUCCESS) {
                GooglePlayServicesUtil.getErrorDialog(status, this, RQS_GooglePlayServices).show();
            }
        } catch (Exception e) {
            Log.e("Error: GooglePlayServiceUtil: ", "" + e);
        }
    }

    // REGISTER A BROADCAST RECEIVER
    IntentFilter localIntentFilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
    localIntentFilter.setPriority(2147483646);
    mReceiver = new SmsReceiver();
    registerReceiver(mReceiver, localIntentFilter);

    try {
        // TRY TO LAUNCH APP RATER 
        AppRater.app_launched(this);
    } catch (Exception e) {
        Log.e("Error AppRater: ", "" + e);
    }

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

    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++) {

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

From source file:com.example.kaow.caltest.MainFrag.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.frag_main);//from   w ww . java2 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());

    final ActionBar actionBar = getActionBar();
    // Specify that the Home button should show an "Up" caret, indicating that touching the
    // button will take the user one step up in the application's hierarchy.
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    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) {
            // 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 < mFoodTitles.length || i < mFoodIcon.length; i++) {
        actionBar.addTab(actionBar.newTab().setIcon(mFoodIcon[i]).setText(mFoodTitles[i]).setTabListener(this));

    }
}

From source file:com.example.adbird.MenuTabActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_menu);// w  w  w.j av a2  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:de.knufficast.ui.main.MainActivity.java

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

    queueFragment = new QueueFragment();
    feedsFragment = new FeedsFragment();

    setContentView(R.layout.activity_main);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

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

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

    // 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.//w w  w  .j a  va 2s  .  c  o  m
    viewPager.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 < sectionsPagerAdapter.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(sectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.example.android.tabbedroombookingtimetabledisplay.MainFragmentActivity.java

@SuppressWarnings("deprecation")
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();

    tabSettings(actionBar);/*  w  w w. ja v  a2s.c om*/

    // 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))
                .setIcon(mAppSectionsPagerAdapter.getPageIcon(i)).setTabListener(this));
    }

    if (!isNetworkAvailable()) {
        createADialog();
    }

}