List of usage examples for android.app ActionBar newTab
@Deprecated public abstract Tab newTab();
From source file:com.jauker.badgeview.example.TabActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tab); // 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); // 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/* w w w . j av a2 s . c om*/ 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++) { Tab tab = actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this); actionBar.addTab(tab); } }
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// w w w .ja v a 2 s .c o m 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:com.linkedin.android.eventsapp.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); pager = new ViewPager(this); pager.setId(R.id.pager);/*from w ww . j a v a 2s . com*/ pager.setOffscreenPageLimit(5); setContentView(pager); final ActionBar bar = getActionBar(); View viewActionBar = getLayoutInflater().inflate(R.layout.layout_action_bar, null); TextView textviewTitle = (TextView) viewActionBar.findViewById(R.id.actionbar_textview); ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER); textviewTitle.setText("UPCOMING EVENTS"); bar.setCustomView(viewActionBar, params); bar.setDisplayShowCustomEnabled(true); bar.setDisplayShowTitleEnabled(false); bar.setIcon(new ColorDrawable(Color.TRANSPARENT)); bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F15153"))); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mEventTabsAdapter = new com.linkedin.android.eventsapp.EventTabsAdapter(this, pager); SimpleDateFormat ft = new SimpleDateFormat("E dd MMM"); ArrayList<Event> events = EventsManager.getInstance(this).getEvents(); for (Event event : events) { String eventDay = ft.format(new Date(event.getEventDate())); mEventTabsAdapter.addTab(bar.newTab().setText(eventDay), EventFragment.class, event); } }
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 w w . ja v a 2 s . c om 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.gieseckedevrient.android.pcscdroid.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); appContext = getApplicationContext(); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOffscreenPageLimit(2); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override// ww w . j a v a 2s . c om public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { actionBar .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } }
From source file:name.gumartinm.weather.information.activity.MainTabsActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.weather_main_tabs); this.mPager = (ViewPager) this.findViewById(R.id.pager); this.mPager.setAdapter(new TabsAdapter(this.getSupportFragmentManager())); this.mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override//from w w w . j a v a 2s . c o m public void onPageSelected(final int position) { MainTabsActivity.this.getActionBar().setSelectedNavigationItem(position); } }); final ActionBar actionBar = this.getActionBar(); PreferenceManager.setDefaultValues(this, R.xml.weather_preferences, false); // Specify that tabs should be displayed in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); actionBar.setDisplayHomeAsUpEnabled(true); // Create a tab listener that is called when the user changes tabs. final ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override public void onTabSelected(final Tab tab, final FragmentTransaction ft) { MainTabsActivity.this.mPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(final Tab tab, final FragmentTransaction ft) { } @Override public void onTabReselected(final Tab tab, final FragmentTransaction ft) { } }; actionBar.addTab(actionBar.newTab().setText(this.getString(R.string.text_tab_currently)) .setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setText(this.getString(R.string.text_tab_five_days_forecast)) .setTabListener(tabListener)); }
From source file:com.bonsai.btcreceive.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Turn off "up" navigation since we are the top-level. getSupportActionBar().setDisplayHomeAsUpEnabled(false); setContentView(R.layout.activity_main); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mAdapter);/* ww w. j av a 2s. c o m*/ // Specify that tabs should be displayed in the action bar. final android.app.ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create a tab listener that is called when the user changes tabs. TabListener tabListener = new TabListener() { @Override public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) { } @Override public void onTabSelected(Tab tab, android.app.FragmentTransaction ft) { // show the given tab int position = tab.getPosition(); manageKeyboard(position); mPager.setCurrentItem(position); } @Override public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) { } }; // Add tabs to the view pager. actionBar.addTab( actionBar.newTab().setText(mRes.getString(R.string.tab_receive)).setTabListener(tabListener)); actionBar.addTab( actionBar.newTab().setText(mRes.getString(R.string.tab_transactions)).setTabListener(tabListener)); actionBar.addTab( actionBar.newTab().setText(mRes.getString(R.string.tab_account)).setTabListener(tabListener)); // Listen for swiped changes to the view pager. mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between pages, select the // corresponding tab. manageKeyboard(position); getActionBar().setSelectedNavigationItem(position); } }); mLogger.info("MainActivity created"); }
From source file:com.native5.plugins.ActionBarPlugin.java
private boolean buildTabs(ActionBar bar, JSONArray definition, String menu_var) { try {//from ww w .ja va2 s .c o m 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")); final boolean isSelected = item_def.optBoolean("selected", false); bar.addTab(bar.newTab().setText(text).setContentDescription(text).setTag(text).setIcon(icon) .setTabListener(new TabListener(this, menu_var + "[" + i + "]")), isSelected); } } catch (JSONException e) { return false; } return true; }
From source file:ru.lizaalert.hotline.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set up the action bar. final ActionBar actionBar = getActionBar(); assert actionBar != null; actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override//from w ww .j a v a2 s. co m public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); if (position == 1) { if (getCurrentFocus() != null) { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService( INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); } } } }); for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { actionBar .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } }
From source file:com.facebook.reflection.SwipeActivity.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()); Intent intent = getIntent();//from ww w. j a v a2 s . com result = intent.getStringArrayListExtra("result"); // 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); // 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); mAppSectionsPagerAdapter.setResult(result); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int 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)); } }