private void setActionBar(ActionBar actionBar) { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab tab1 = actionBar.newTab(); tab1.setText("Home"); tab1.setTabListener(this); actionBar.addTab(tab1); ActionBar.Tab tab2 = actionBar.newTab(); tab2.setText("Favorite"); tab2.setTabListener(this); actionBar.addTab(tab2); }
public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) { TabInfo info = new TabInfo(clss, args); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBar.addTab(tab); notifyDataSetChanged(); }
@Override public void addTab(TabProxy tabProxy) { ActionBar.Tab tab = actionBar.newTab(); tab.setTabListener(this); // Create a view for this tab proxy. TiUIActionBarTab actionBarTab = new TiUIActionBarTab(tabProxy, tab); tabProxy.setView(actionBarTab); // Add the new tab, but don't select it just yet. // The selected tab is set once the group is done opening. actionBar.addTab(tab, false); tabGroupPagerAdapter.notifyDataSetChanged(); int numTabs = actionBar.getTabCount(); int offscreen = numTabs > 1 ? numTabs - 1 : 1; // Must be at least 1 tabGroupViewPager.setOffscreenPageLimit(offscreen); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState == null) { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); sdf.setTimeZone(TimeZone.getTimeZone("EST5EDT")); String now = sdf.format(date); prefs = getSharedPreferences(prefName, MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putString(ACTIVE_KEY, now); editor.commit(); db = new TableDbAdapter(getApplicationContext()); try { if (getIntent().getExtras().getString("type").equals("usercheck")) { Toast.makeText( getBaseContext(), "Welcome back, " + prefs.getString(KEY_USERNAME, "") + "!", Toast.LENGTH_SHORT) .show(); } } catch (NullPointerException e) { // TODO: handle exception e.printStackTrace(); } } setContentView(R.layout.main); actionBar = getSupportActionBar(); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); if (metrics.heightPixels < 400 && metrics.widthPixels < 300) { actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayShowHomeEnabled(false); } else { actionBar.setDisplayUseLogoEnabled(true); } actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab tabCalendar = actionBar.newTab().setText("Calendar"); ActionBar.Tab tabTotals = actionBar.newTab().setText("Totals"); ActionBar.Tab tabDetails = actionBar.newTab().setText("User Info"); Fragment fragmentCalendar = new FragmentCalendar(); Fragment fragmentTotals = new FragmentTotals(); Fragment fragmentDetails = new FragmentDetails(); tabCalendar.setTabListener(new MyTabsListener(fragmentCalendar)); tabTotals.setTabListener(new MyTabsListener(fragmentTotals)); tabDetails.setTabListener(new MyTabsListener(fragmentDetails)); actionBar.addTab(tabCalendar); actionBar.addTab(tabTotals); actionBar.addTab(tabDetails); }