List of usage examples for android.app ActionBar addTab
@Deprecated public abstract void addTab(Tab tab);
From source file:es.farfuteam.vncpp.controller.ActivityTabs.java
/** * @param savedInstanceState//w w w. java 2 s . c om * @brief This is the onCreate method * @details The onCreate method adds an actionBar to the activity with two tabs (recent and favorites). * It also load the preferences file into the prefs attribute and sets the rememeberExit attribute. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tab_host); final ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME); final String recents = getString(R.string.recents); final String favorites = getString(R.string.favoritesTab); // add tabs Tab tab1 = actionBar.newTab().setText(recents) .setTabListener(new TabListener<ListFragmentTab>(this, "tab1", ListFragmentTab.class)); actionBar.addTab(tab1); Tab tab2 = actionBar.newTab().setText(favorites) .setTabListener(new TabListener<ListFragmentTabFav>(this, "tab2", ListFragmentTabFav.class)); actionBar.addTab(tab2); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); //accedemos a fichero preferencias (Configuration.getInstance()).setPrefs(getSharedPreferences("PreferencesFile", Context.MODE_PRIVATE)); (Configuration.getInstance()).readPrefs(); // Orientation Change Occurred if (savedInstanceState != null) { int currentTabIndex = savedInstanceState.getInt("tab_index"); actionBar.setSelectedNavigationItem(currentTabIndex); } //nombre en la activity bar final String title = getString(R.string.connections); setTitle(title); }
From source file:ca.ramnansingh.randy.ibmwatsonspeechqa.AudioRecordTest.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Strictmode needed to run the http/wss request for devices > Gingerbread if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }/*from w ww . j ava 2 s . c o m*/ //setContentView(R.layout.activity_main); setContentView(R.layout.activity_tab_text); ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); tabSTT = actionBar.newTab().setText("Speech to Text"); tabTTS = actionBar.newTab().setText("Text to Speech"); tabSTT.setTabListener(new MyTabListener(fragmentTabSTT)); tabTTS.setTabListener(new MyTabListener(fragmentTabTTS)); actionBar.addTab(tabSTT); actionBar.addTab(tabTTS); //actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#B5C0D0"))); }
From source file:com.example.android.foodstorm.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); dataSource = new FoodSQLiteHelper(this); // 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(); actionBar.setHomeButtonEnabled(false); // no home/up button 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//ww w .jav a 2s . com public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); actionBar.addTab(actionBar.newTab().setIcon(R.drawable.fridge_main).setTabListener(this)); actionBar.addTab(actionBar.newTab().setIcon(R.drawable.chef_hat).setTabListener(this)); }
From source file:com.github.wakhub.monodict.activity.FlashcardActivity.java
@UiThread void reloadTabs() { Map<Integer, Integer> countsForBoxes; try {//from w w w . j ava 2 s .c o m countsForBoxes = databaseHelper.getCountsForBoxes(); } catch (SQLException e) { activityHelper.showError(e); return; } ActionBar actionBar = getActionBar(); for (int i = 0; i < Card.BOX_MAX; i++) { ActionBar.Tab tab; if (actionBar.getTabCount() > i) { tab = actionBar.getTabAt(i); } else { tab = actionBar.newTab().setTag(i).setTabListener(this); actionBar.addTab(tab); } int box = i + 1; String label = String.format("BOX%d", box); if (i == 0) { label = "INBOX"; } if (countsForBoxes.keySet().contains(box)) { label += String.format("(%d)", countsForBoxes.get(box)); } tab.setText(label); } if (!isTabInitialized || isReloadRequired) { isTabInitialized = true; isReloadRequired = false; // TODO: not working int index = state.getBox() - 1; if (index < 0 || actionBar.getTabCount() < index) { index = 0; } actionBar.getTabAt(index).select(); loadContents(); } }
From source file:com.piusvelte.mosaic.android.Main.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//from w w w.j a v a 2s . c om pagerAdapter = new MosaicPagerAdapter(getSupportFragmentManager()); final ActionBar actionBar = getActionBar(); // actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(pagerAdapter); viewPager.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 (int i = 0; i < pagerAdapter.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(pagerAdapter.getPageTitle(i)).setTabListener(this)); } }
From source file:com.ibm.msg.android.ConnectionDetails.java
/** * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle) *//* www.j a va 2 s . c om*/ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); clientHandle = getIntent().getStringExtra("handle"); setContentView(R.layout.activity_connection_details); // Create the adapter that will return a fragment for each of the pages sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the action bar for tab navigation final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // add the sectionsPagerAdapter viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(sectionsPagerAdapter); viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // select the tab that represents the current page actionBar.setSelectedNavigationItem(position); } }); // Create the tabs for the screen for (int i = 0; i < sectionsPagerAdapter.getCount(); i++) { ActionBar.Tab tab = actionBar.newTab(); tab.setText(sectionsPagerAdapter.getPageTitle(i)); tab.setTabListener(this); actionBar.addTab(tab); } connection = Connections.getInstance(this).getConnection(clientHandle); changeListener = new ChangeListener(); connection.registerChangeListener(changeListener); }
From source file:com.indragie.cmput301as1.ExpenseClaimListActivity.java
/** * Set up fragments to display expense claim data. *//*w w w . jav a 2 s .c om*/ private void setupFragments() { User user = userManager.getActiveUser(); Session session = new Session(this, user); Session.setSharedSession(session); pagerAdapter = new ExpenseClaimPagerAdapter(this, getSupportFragmentManager(), user); pager.setAdapter(pagerAdapter); // From http://developer.android.com/training/implementing-navigation/lateral.html final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.TabListener tabListener = new ActionBar.TabListener() { public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { pager.setCurrentItem(tab.getPosition()); } public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { } public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { } }; pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); Tab ownedTab = actionBar.newTab().setText(R.string.tab_owned).setTabListener(tabListener); Tab reviewalTab = actionBar.newTab().setText(R.string.tab_reviewal).setTabListener(tabListener); actionBar.addTab(ownedTab); actionBar.addTab(reviewalTab); }
From source file:com.polychrom.cordova.ActionBarPlugin.java
private boolean buildTabs(ActionBar bar, JSONArray definition, String menu_var) { try {// w w w. jav a 2s. c om for (int i = 0; i < definition.length(); ++i) { final JSONObject item_def = definition.getJSONObject(i); final String text = item_def.isNull("text") ? "" : item_def.getString("text"); final Drawable icon = item_def.isNull("icon") ? null : getDrawableForURI(item_def.getString("icon")); bar.addTab(bar.newTab().setText(text).setIcon(icon) .setTabListener(new TabListener(this, menu_var + "[" + i + "]"))); } } catch (JSONException e) { return false; } return true; }
From source file:de.grobox.liberario.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.pager); final ActionBar actionBar = getActionBar(); // Specify that tabs should be displayed in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create a tab listener that is called when the user changes tabs. ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override/* www . j av a 2 s . c om*/ public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { // show the given tab mViewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { // hide the given tab } @Override public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { // probably ignore this event } }; List<String> fragments = new ArrayList<String>(); fragments.add(DirectionsFragment.class.getName()); actionBar.addTab( actionBar.newTab().setIcon(android.R.drawable.ic_menu_directions).setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ic_action_star).setTabListener(tabListener)); fragments.add(FavTripsFragment.class.getName()); actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ic_tab_stations).setTabListener(tabListener)); fragments.add(StationsFragment.class.getName()); mainPagerAdapter = new MainPagerAdapter(getSupportFragmentManager(), this, fragments); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between pages, select the corresponding tab. getActionBar().setSelectedNavigationItem(position); } }); mViewPager.setAdapter(mainPagerAdapter); // show Changelog HoloChangeLog cl = new HoloChangeLog(this); if (cl.isFirstRun() && !cl.isFirstRunEver()) { cl.getLogDialog().show(); } }
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/*from www. j a v a 2 s . c om*/ 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)); } }