List of usage examples for android.app ActionBar newTab
@Deprecated public abstract Tab newTab();
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 w ww . ja v a2 s .c om 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.groksolutions.grok.mobile.HourDayWeekActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getResourceView());/*from ww w .j ava 2 s .co m*/ // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayShowTitleEnabled(false); Locale l = Locale.getDefault(); // For each of the sections in the app, add a tab to the action bar. // Add the "Fragment" class to the tab's tag. The tab's "Fragment" will // be created using this class // Hour Page actionBar.addTab(actionBar.newTab().setText(getString(R.string.title_tab_hour).toUpperCase(l)) .setTabListener(this).setTag(AggregationType.Hour)); // Day Page actionBar.addTab(actionBar.newTab().setText(getString(R.string.title_tab_day).toUpperCase(l)) .setTabListener(this).setTag(AggregationType.Day)); // Week Page actionBar.addTab(actionBar.newTab().setText(getString(R.string.title_tab_week).toUpperCase(l)) .setTabListener(this).setTag(AggregationType.Week)); // Create the fragment adapter that will return a fragment based on the // Fragment class attached to the tab's tag object final FragmentPagerAdapter pagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { final Fragment[] _fragments = new Fragment[3]; @Override public Fragment getItem(int position) { Tab tab = actionBar.getTabAt(position); if (tab != null) { if (_fragments[position] == null) { _fragments[position] = createTabFragment(tab); } } return _fragments[position]; } @Override public int getCount() { return actionBar.getTabCount(); } }; // Set up the ViewPager with the sections adapter. _viewPager = (ViewPager) findViewById(R.id.pager); _viewPager.setAdapter(pagerAdapter); // Keep all pages in memory _viewPager.setOffscreenPageLimit(2); // 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. _viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); }
From source file:org.dmfs.webcal.fragments.MyCalendarsFragment.java
private void setupActionBarTabs() { ActionBar actionBar = getActivity().getActionBar(); int tabCount = actionBar.getTabCount(); int pageCount = mAdapter.getCount(); // replace titles and listeners of existing tabs int i = 0;//from w w w. j a v a 2 s . c o m for (; i < tabCount && i < pageCount; ++i) { final Tab tab = actionBar.getTabAt(i); tab.setText(mAdapter.getPageTitle(i)); tab.setTabListener(this); } // add missing tabs for (; i < pageCount; ++i) { actionBar.addTab(actionBar.newTab().setText(mAdapter.getPageTitle(i)).setTabListener(this)); } // remove remaining tabs for (; i < tabCount; --tabCount) { actionBar.removeTabAt(i); } if (pageCount > 1) { int selection = mSelectedTab; // changing the navigation mode might trigger a call to onTabSelected, overriding mSelectedTab with a wrong value, so save it actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mSelectedTab = selection; if (selection < pageCount) { mViewPager.setCurrentItem(selection, false); } } else { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); } }
From source file:fr.android.earthdawn.activities.CharacterSheetActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager);/* w w w . ja v a 2 s . co m*/ setContentView(mViewPager); final ActionBar bar = getActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE); mTabsAdapter = new TabsAdapter(this, mViewPager); // Load character and store it in bundle final EDCharacter character = CharacterManager.getLoadedCharacter(); Bundle bundle; // Infos gnrales mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_description), CharacterFragment.class, null); // Talents, par discipline if (character.getMainDiscipline() != null) { bundle = new Bundle(1); bundle.putSerializable(Constants.BUNDLE_DISCIPLINE, character.getMainDiscipline()); mTabsAdapter.addTab(bar.newTab().setText(character.getMainDiscipline().getName()), TalentsFragment.class, bundle); } if (character.getSecondDiscipline() != null) { bundle = new Bundle(1); bundle.putSerializable(Constants.BUNDLE_DISCIPLINE, character.getSecondDiscipline()); mTabsAdapter.addTab(bar.newTab().setText(character.getSecondDiscipline().getName()), TalentsFragment.class, bundle); } if (character.getThirdDiscipline() != null) { bundle = new Bundle(1); bundle.putSerializable(Constants.BUNDLE_DISCIPLINE, character.getThirdDiscipline()); mTabsAdapter.addTab(bar.newTab().setText(character.getThirdDiscipline().getName()), TalentsFragment.class, bundle); } // Equipment mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_stuff), EquipmentFragment.class, null); // Skill mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_skills), SkillsFragment.class, null); // TODO Grimoire if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt(TAB, 0)); } }
From source file:org.kanbansalad.scanner.client.android.ScanActivity.java
private void addTabsTo(final ActionBar actionBar) { // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < tabPagerAdapter.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(tabPagerAdapter.getPageTitle(i)).setTabListener(this)); }//from w ww .ja v a 2 s . c o m }
From source file:co.edu.uniajc.vtf.content.SwipeContentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_swipe_content); //get the pager this.coAppSectionsPagerAdapter = new AppSectionsPagerAdapter(this.getSupportFragmentManager(), this); this.coViewPager = (ViewPager) findViewById(R.id.pagPagerContainer); this.coViewPager.setAdapter(coAppSectionsPagerAdapter); //get the action bar final ActionBar actionBar = this.getActionBar(); coViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override/*from w w w . j ava 2 s. c o m*/ public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.addTab(actionBar.newTab().setTabListener(this).setIcon(R.drawable.list48)); actionBar.addTab(actionBar.newTab().setTabListener(this).setIcon(R.drawable.map48)); actionBar.addTab(actionBar.newTab().setTabListener(this).setIcon(R.drawable.ra48)); actionBar.addTab(actionBar.newTab().setTabListener(this).setIcon(R.drawable.options48)); //get the google api client this.coApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(Plus.API).addScope(Plus.SCOPE_PLUS_PROFILE).build(); }
From source file:com.bignerdranch.android.fragmentbasics.NewsReaderActivity.java
/** Sets up Action Bar (if present). * * @param showTabs whether to show tabs (if false, will show list). * @param selTab the selected tab or list item. *//*from ww w . j a v a2 s .co m*/ public void setUpActionBar(boolean showTabs, int selTab) { if (Build.VERSION.SDK_INT < 11) { // No action bar for you! // But do not despair. In this case the layout includes a bar across the // top that looks and feels like an action bar, but is made up of regular views. return; } android.app.ActionBar actionBar = getActionBar(); actionBar.setDisplayShowTitleEnabled(false); // Set up a CompatActionBarNavHandler to deliver us the Action Bar nagivation events CompatActionBarNavHandler handler = new CompatActionBarNavHandler(this); if (showTabs) { actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_TABS); int i; for (i = 0; i < CATEGORIES.length; i++) { actionBar.addTab(actionBar.newTab().setText(CATEGORIES[i]).setTabListener(handler)); } actionBar.setSelectedNavigationItem(selTab); } else { actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_LIST); SpinnerAdapter adap = new ArrayAdapter<String>(this, R.layout.actionbar_list_item, CATEGORIES); actionBar.setListNavigationCallbacks(adap, handler); } // Show logo instead of icon+title. actionBar.setDisplayUseLogoEnabled(true); }
From source file:com.decad3nce.aegis.AegisActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager);//w w w .j av a 2s .co m setContentView(mViewPager); final ActionBar bar = getActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); bar.setDisplayShowHomeEnabled(true); bar.setHomeButtonEnabled(true); bar.setTitle(R.string.app_name); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bar.newTab().setText(R.string.alarm_section), SMSAlarmFragment.class, null); mTabsAdapter.addTab(bar.newTab().setText(R.string.lock_section), SMSLockFragment.class, null); mTabsAdapter.addTab(bar.newTab().setText(R.string.wipe_section), SMSWipeFragment.class, null); mTabsAdapter.addTab(bar.newTab().setText(R.string.locate_section), SMSLocateFragment.class, null); if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0)); } final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); alarmEnabled = preferences.getBoolean(PREFERENCES_ALARM_ENABLED, this.getResources().getBoolean(R.bool.config_default_alarm_enabled)); wipeEnabled = preferences.getBoolean(PREFERENCES_WIPE_ENABLED, this.getResources().getBoolean(R.bool.config_default_wipe_enabled)); lockEnabled = preferences.getBoolean(PREFERENCES_LOCK_ENABLED, this.getResources().getBoolean(R.bool.config_default_lock_enabled)); locateEnabled = preferences.getBoolean(PREFERENCES_LOCATE_ENABLED, this.getResources().getBoolean(R.bool.config_default_locate_enabled)); invalidateOptionsMenu(); mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); }
From source file:com.stj.fileexplorer.FileExplorerTabActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // add begin by xugaoming@20140317, don't need to restore // fragments automaticaly if killed by system for memory, // it will mess up the logic savedInstanceState = null;/*from ww w .j a v a 2 s .co m*/ // add end super.onCreate(savedInstanceState); StorageHelper.getInstance(this); setContentView(R.layout.fragment_pager); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setOffscreenPageLimit(DEFAULT_OFFSCREEN_PAGES); final ActionBar bar = getActionBar(); bar.hide(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME); mTabsAdapter = new TabsAdapter(this, mViewPager); // mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_category), // FileCategoryActivity.class, null); mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_sd), FileViewActivity.class, null); FileViewActivity fileViewActivity = ((FileViewActivity) getFragment(Util.SDCARD_TAB_INDEX)); fileViewActivity.registBottomBtnPressListener(this); /*mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_remote), ServerControlActivity.class, null);*/ int selectedItem = PreferenceManager.getDefaultSharedPreferences(this).getInt(INSTANCESTATE_TAB, Util.CATEGORY_TAB_INDEX); if (Intent.ACTION_PICK.equals(getIntent().getAction())) { selectedItem = Util.SDCARD_TAB_INDEX; } //add begin by xugaoming@20140517, add function to locate //to a directory Intent intent = getIntent(); if (intent != null && intent.getStringExtra("goto_dir") != null) { selectedItem = Util.SDCARD_TAB_INDEX; } //add end bar.setSelectedNavigationItem(0); }
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.// ww w .j a va2s .c o 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)); }