List of usage examples for android.app ActionBar setSelectedNavigationItem
@Deprecated public abstract void setSelectedNavigationItem(int position);
From source file:net.forkk.autocron.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); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); // 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//from w w w . ja va2 s .com 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. 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(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } }
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 ww w . j a va 2 s. c o m 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.example.routerecorder.FragmentTabs.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); instance = this; final ActionBar bar = getActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE); //bar.setDisplayShowCustomEnabled(true); //bar.setDisplayShowTitleEnabled(false); //bar.setDisplayShowHomeEnabled(false); bar.setDisplayShowCustomEnabled(false); bar.addTab(bar.newTab().setText("Show Map") .setTabListener(new TabListener<RouteMapFragment>(this, "Show Map", RouteMapFragment.class))); bar.addTab(bar.newTab().setText("Add Trip") .setTabListener(new TabListener<AddRouteFragment>(this, "Add Trip", AddRouteFragment.class))); bar.addTab(bar.newTab().setText("Show List") .setTabListener(new TabListener<MyListFragment>(this, "Show List", MyListFragment.class))); if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0)); }/*from www . j ava 2 s .c om*/ //FragmentManager manager = getSupportFragmentManager(); //fragmentA = (RouteMapFragment) manager.findFragmentById(R.id.map); //fragmentB = (AddRouteFragment) manager.findFragmentById(R.id.fragment_container); }
From source file:com.example.emulator8051.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); // 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.*/// w w w .j a va2 s . c o m 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. 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(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } }
From source file:com.otaupdater.TabDisplay.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context context = getApplicationContext(); cfg = Config.getInstance(context);/*w w w . java 2 s . c o m*/ if (!Utils.haveProKey(context)) { cfg.setKeyExpiry(0); } else if (!cfg.hasValidProKey()) { if (cfg.isProKeyTemporary()) { if (cfg.getKeyExpires() < System.currentTimeMillis()) { Utils.verifyProKey(context); } } else { Utils.verifyProKey(context); } } if (!Utils.isRomOtaEnabled() && !Utils.isKernelOtaEnabled()) { if (!cfg.getIgnoredUnsupportedWarn()) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.alert_unsupported_title); alert.setMessage(R.string.alert_unsupported_message); alert.setCancelable(false); alert.setNegativeButton(R.string.alert_exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); alert.setPositiveButton(R.string.alert_ignore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cfg.setIgnoredUnsupportedWarn(true); dialog.dismiss(); } }); alert.create().show(); } if (Utils.marketAvailable(this)) { GCMRegistrar.checkDevice(context); GCMRegistrar.checkManifest(context); final String regId = GCMRegistrar.getRegistrationId(context); if (regId.length() != 0) { GCMRegistrar.unregister(context); } } } else { if (Utils.marketAvailable(this)) { GCMRegistrar.checkDevice(context); GCMRegistrar.checkManifest(context); final String regId = GCMRegistrar.getRegistrationId(context); if (regId.length() != 0) { if (cfg.upToDate()) { Log.v(Config.LOG_TAG + "GCMRegister", "Already registered"); } else { Log.v(Config.LOG_TAG + "GCMRegister", "Already registered, out-of-date"); cfg.setValuesToCurrent(); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { Utils.updateGCMRegistration(context, regId); return null; } }.execute(); } } else { GCMRegistrar.register(context, Config.GCM_SENDER_ID); Log.v(Config.LOG_TAG + "GCMRegister", "GCM registered"); } } else { UpdateCheckReceiver.setAlarm(context); } } mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); final ActionBar bar = getActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); bar.setTitle(R.string.app_name); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bar.newTab().setText(R.string.main_about), AboutTab.class, null); mTabsAdapter.addTab(bar.newTab().setText(R.string.main_rom), ROMTab.class, null); mTabsAdapter.addTab(bar.newTab().setText(R.string.main_kernel), KernelTab.class, null); mTabsAdapter.addTab(bar.newTab().setText(R.string.main_walls), WallsTab.class, null); if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0)); } }
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//from w w w. j a v a 2 s .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.microsoft.band.sdksample.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(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. 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//from w w w .ja v 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++) { // 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(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } }
From source file:net.sakuramilk.kbcupdater.MainFragmentActivity.java
/** Called when the activity is first created. */ @Override// w ww . j a v a 2 s . c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.viewpager); setContentView(mViewPager); final ActionBar bar = getActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); bar.setTitle(R.string.app_name); mPagerAdapter = new TabsFragmentAdapter(this, mViewPager); Bundle args = new Bundle(); args.putString("url", Constant.LIST_URL_SC06D); mPagerAdapter.addTab(bar.newTab().setText("SC-06D"), DeviceFragmentActivity.class, args); /* args = new Bundle(); args.putString("url", "https://github.com/kbc-developers/release/wiki/sc04d"); mPagerAdapter.addTab(bar.newTab().setText("SC-04D"), DeviceFragmentActivity.class, args); */ args = new Bundle(); args.putString("url", Constant.LIST_URL_SC02C); mPagerAdapter.addTab(bar.newTab().setText("SC-02C"), DeviceFragmentActivity.class, args); if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0)); } }
From source file:net.forkk.autocron.EditAutomationActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent();/* ww w. j av a 2 s . c o m*/ assert intent != null; mAutomationPointer = (ComponentPointer) intent.getSerializableExtra(EXTRA_AUTOMATION_POINTER); mShowTriggerList = mAutomationPointer instanceof Event.Pointer; setContentView(R.layout.activity_edit_automation); // Set up the action bar. final ActionBar actionBar = getActionBar(); assert actionBar != null; actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mPagerAdapter); // 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 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 < mPagerAdapter.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(mPagerAdapter.getPageTitle(i)).setTabListener(this)); } }
From source file:org.messic.android.activities.BaseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_base); // 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 activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); // 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 ww .j ava2 s .co 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++) { // 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(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } }