Example usage for android.app ActionBar NAVIGATION_MODE_TABS

List of usage examples for android.app ActionBar NAVIGATION_MODE_TABS

Introduction

In this page you can find the example usage for android.app ActionBar NAVIGATION_MODE_TABS.

Prototype

int NAVIGATION_MODE_TABS

To view the source code for android.app ActionBar NAVIGATION_MODE_TABS.

Click Source Link

Document

Tab navigation mode.

Usage

From source file:com.xortech.sender.SenderMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sender_main);

    // REMOVE THE TITLE FROM THE ACTIONBAR
    getActionBar().setDisplayShowTitleEnabled(false);

    preferences = PreferenceManager.getDefaultSharedPreferences(this);

    mapType = preferences.getString("mapType", GMAPS);

    // CHECK FOR "DON'T KEEP ACTIVITIES" IN DEVELOPER OPTIONS
    boolean checkDeveloper = isAlwaysFinishActivitiesOptionEnabled();
    if (checkDeveloper) {
        showDeveloperOptionsScreen();/* w w w  . j av  a2s. c  o  m*/
    }

    /*
     * IF GOOGLE MAPS IS SELECTED AS THE DEFAULT, THEN CHECK TO
     * SEE IF THE USER HAS THE CORRECT VERSION OF GOOGLE PLAY SERVICES
     */
    if (mapType.equals(GMAPS)) {
        // GET GOOGLE PLAY STATUS
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

        // CHECK IF GOOGLE PLAY SERVICE IS AVAILABLE 
        try {
            if (status != ConnectionResult.SUCCESS) {
                GooglePlayServicesUtil.getErrorDialog(status, this, RQS_GooglePlayServices).show();
            }
        } catch (Exception e) {
            Log.e("Error: GooglePlayServiceUtil: ", "" + e);
        }
    }

    // REGISTER A BROADCAST RECEIVER
    IntentFilter localIntentFilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
    localIntentFilter.setPriority(2147483646);
    mReceiver = new SmsReceiver();
    registerReceiver(mReceiver, localIntentFilter);

    try {
        // TRY TO LAUNCH APP RATER 
        AppRater.app_launched(this);
    } catch (Exception e) {
        Log.e("Error AppRater: ", "" + e);
    }

    // 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);

    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++) {

        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.lambdal.railgun.PInfo.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set the activity
    PInfo.activity = this;
    int packageCount = PInfo.getPackages().size();

    // Hide the status bar.
    Window w = getWindow();//  w  ww .  ja v  a 2  s  .c om
    w.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    w.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    setContentView(R.layout.activity_main);
    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.hide();
    // getActionBar().setBackgroundDrawable(new
    // ColorDrawable(Color.argb(128, 0, 0, 0)));
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    mSectionsPagerAdapter.pageCount = packageCount;

    // 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
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    mViewPager.setOnClickListener(new ViewPager.OnClickListener() {
        @Override
        public void onClick(View view) {
            // When swiping between pages, select the
            // corresponding tab.
            int currentAppIndex = DummySectionFragment.currentAppIndex;
            ArrayList<PInfo> appList = PInfo.getInstalledApps(false);
            PInfo app = appList.get(currentSelectedTabIndex.intValue());
            // Open the app:
            Intent launchIntent = getPackageManager().getLaunchIntentForPackage(app.pname);
            try {
                startActivity(launchIntent);
            } catch (Exception e) {
                Log.v("We ran into an exception when launching intent: " + app.pname, e.toString());
            }
            Log.v("We have a tap event which happened at index: ",
                    app.toString() + " " + currentSelectedTabIndex.toString());
        }
    });

    for (int i = 0; i < PInfo.getPackages().size(); i++) {
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:org.ounl.lifelonglearninghub.nfcecology.fcube.navigate.SwipeFragmentActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pager);

    // Create the adapter that will return a fragment for each of the three
    // primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Actvate home button
    final ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(true);

    // Specify that we will be displaying tabs in the action bar.
    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  . ja  v a  2 s.  com*/
        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 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));
    }

}

From source file:it.durip_app.GraphActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_graph);
    data = new DataSource();
    // Get the message from the intent
    Intent intent = getIntent();/*w w w . j a va 2  s .  c o m*/
    String paramUrl = intent.getStringExtra(MainActivity.PARAM_URL);
    int paramT = intent.getIntExtra(MainActivity.PARAM_T, 200);
    int paramI = intent.getIntExtra(MainActivity.PARAM_I, 5);
    int paramPort = intent.getIntExtra(MainActivity.PARAM_PORT, 4000);
    int paramVerbose = intent.getIntExtra(MainActivity.PARAM_VERBOSE, 1);
    data.setUrl(paramUrl);
    data.setT(paramT);
    data.setI(paramI);
    data.setPort(paramPort);
    data.setVerbose(paramVerbose);

    // kick off the data generating thread:
    mySource = new Thread(data);
    mySource.start();

    // 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();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    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
        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 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));
    }
    // Show the Up button in the action bar.

}

From source file:com.packetsender.android.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mContext = getApplicationContext();/*from w  w  w.ja va2 s  .  co  m*/
    serviceIntent = new Intent(mContext, PacketListenerService.class);
    activeMenu = R.menu.packetlistmenu;

    trafficLogPackets = new ArrayList<Packet>();

    dataStore = new DataStorage(getSharedPreferences(DataStorage.PREFS_SETTINGS_NAME, 0),
            getSharedPreferences(DataStorage.PREFS_SAVEDPACKETS_NAME, 0),
            getSharedPreferences(DataStorage.PREFS_SERVICELOG_NAME, 0),
            getSharedPreferences(DataStorage.PREFS_MAINTRAFFICLOG_NAME, 0));

    dataStore.clearServicePackets();

    // 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
        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));
    }

    startListenerService();

    wifiActive = DataStorage.isWifiActive(mContext);
    ipAddress = "";

    if (wifiActive) {
        ipAddress = DataStorage.getIP(mContext);
        Toast.makeText(mContext, "Your IP is " + ipAddress, Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(mContext, "Send only. Wifi is inactive.", Toast.LENGTH_LONG).show();
    }

    //periodically poll the traffic log

    trafficLogPolling = new Runnable() {
        public void run() {

            String msg = dataStore.getToast();
            if (!msg.isEmpty()) {
                Toast.makeText(mContext, msg, Toast.LENGTH_LONG).show();
            }

            Packet[] trafficPackets = dataStore.fetchAllTrafficLogPackets();
            if (trafficPackets.length != trafficLogPackets.size()) {
                trafficLogPackets.clear();
                trafficLogPackets.addAll(Arrays.asList(trafficPackets));
                updateTrafficPacketsList(trafficFragmentView);
                //trafficFragmentView

            }

            //Log.d("main", DataStorage.FILE_LINE( "trafficLogPolling."));
            mHandler.postDelayed(trafficLogPolling, 1100);
        }
    };

    //periodically monitor Wi-Fi
    updateWifi = new Runnable() {
        public void run() {

            boolean checkWifi = DataStorage.isWifiActive(mContext);
            if (checkWifi != wifiActive) {
                if (checkWifi) {
                    ipAddress = DataStorage.getIP(mContext);
                    Toast.makeText(mContext, "Your IP is " + ipAddress, Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(mContext, "Wifi is not active", Toast.LENGTH_LONG).show();
                }

                wifiActive = checkWifi;

            }
            mHandler.postDelayed(updateWifi, 5000);
        }
    };

    mHandler.postDelayed(updateWifi, 5000);
    mHandler.postDelayed(trafficLogPolling, 700);
    //setup saved List periodic check
    updateSavedLists = new Runnable() {
        public void run() {
            if (dataStore.isInvalidateLists()) {

                Log.d("main", DataStorage.FILE_LINE("Found invalid lists."));
                updateSavedPacketsList(packetsFragmentView);
                dataStore.clearInvalidateLists();
            }

            mHandler.postDelayed(updateSavedLists, 2000);
        }
    };

    mHandler.postDelayed(updateSavedLists, 7000);

}

From source file:com.mplayer_remote.RemoteControl.java

/**Metoda wywoywana przez system Android przy starcie aktywnoci.
 * Wczytuje definicje GUI z pliku XML. Definiuje akcje wywoywane poprzez interakcji uytkownika z graficznym interfejsem uytkownika aktywnoci.
 * Definiuje <code>progressHandler</code>, <code>timeLengthTextViewUpdateHandler</code>, <code>timePositionUpdateHandler</code>.
 * @see android.app.Activity#onCreate(android.os.Bundle)
 *//*from   ww w. j  av  a2 s  .c  o m*/

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //getActionBar().setDisplayHomeAsUpEnabled(false);

    Intent intentFromstartActivity = getIntent(); //getIntent() zwraca obiekt Intent ktry wystartowa Activity
    fileToPlayString = intentFromstartActivity.getStringExtra("file_to_play");
    absolutePathString = intentFromstartActivity.getStringExtra("absolute_path");

    //gui
    setContentView(R.layout.layout_for_remotecontrol);
    myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
    mViewPager = (ViewPager) findViewById(R.id.pager);
    Log.v(TAG, "mViewPager" + mViewPager.toString());
    Log.v(TAG, "myFragmentPagerAdapter" + myFragmentPagerAdapter.toString());
    mViewPager.setAdapter(myFragmentPagerAdapter);
    //tabs
    actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        @Override
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
            mViewPager.setCurrentItem(tab.getPosition(), true);
        }

        @Override
        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {

        }

        @Override
        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {

        }
    };
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });
    ActionBar.Tab nowPlayingTab = actionBar.newTab();
    nowPlayingTab.setText(R.string.title_for_now_playing_tab);
    nowPlayingTab.setTabListener(tabListener);
    actionBar.addTab(nowPlayingTab);
    ActionBar.Tab playlistTab = actionBar.newTab();
    playlistTab.setText(R.string.title_for_playlist_tab);
    playlistTab.setTabListener(tabListener);
    actionBar.addTab(playlistTab);
}

From source file:com.repay.android.frienddetails.FriendDetailsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // If the available screen size is that of an average tablet (as defined
    // in the Android documentation) then allow the screen to rotate
    if (getResources().getBoolean(R.bool.lock_orientation)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }//from  w w w  . j  a va2 s  .  c o  m

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_frienddetails);
    mDB = new DatabaseHandler(this);
    getActionBar().setDisplayShowTitleEnabled(false);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    Bundle bundle = getIntent().getExtras();
    try {
        if (bundle != null) {
            mFriend = new Friend(bundle.getString(Friend.REPAYID),
                    Uri.parse(bundle.getString(Friend.LOOKUPURI)), bundle.getString(Friend.NAME),
                    new BigDecimal(bundle.getString(Friend.AMOUNT)));
        }
    } catch (NullPointerException e) {
        Log.i(TAG, "Person added by name, not from contacts list");
        if (bundle != null) {
            mFriend = new Friend(bundle.getString(Friend.REPAYID), null, bundle.getString(Friend.NAME),
                    new BigDecimal(bundle.getString(Friend.AMOUNT)));
        }
    }

    // Set the message for the info dialog
    mInfoMessage = R.string.activity_debtHistoryInfoDialog_message_debtHistoryInfo;

    // See if we need to use a tab view or just a 2 fragment layout,
    // this boolean is stored in XML, this way I can use the SDK
    // size qualifiers to determine phone or tablet
    mUseTabs = getResources().getBoolean(R.bool.use_tabView);

    // Determine whether this is a tablet or not so
    // we know if we need the tab view or just a couple
    // of FrameLayouts
    if (!mUseTabs) {
        mFragMan = getSupportFragmentManager().beginTransaction();
        mOverViewFrag = new FriendOverviewFragment();
        mDebtHistoryFrag = new DebtHistoryFragment();
        mFragMan.add(R.id.activity_frienddetails_frame1, mOverViewFrag);
        mFragMan.add(R.id.activity_frienddetails_frame2, mDebtHistoryFrag);
        mFragMan.commit();

    } else {
        mTabView = (ViewPager) findViewById(R.id.activity_frienddetails_tabView);
        // Get the friend from the bundle passed in the intent

        // Produce the Tab bar
        mActionBar = getActionBar();
        if (mActionBar != null) {
            mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        }
        ViewPager.SimpleOnPageChangeListener mViewPagerListener = new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                // Find the ViewPager Position
                mActionBar.setSelectedNavigationItem(position);
            }
        };
        mTabView.setOnPageChangeListener(mViewPagerListener);
        // Set the ViewPager animation
        mTabView.setPageTransformer(true, new DepthPageTransformer());
        // Capture tab button clicks
        ActionBar.TabListener tabListener = new ActionBar.TabListener() {

            @Override
            public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {
                // Not needed
            }

            @Override
            public void onTabSelected(Tab tab, android.app.FragmentTransaction ft) {
                mTabView.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {
                // Not needed
            }
        };

        // Create first Tab
        Tab mTab1 = mActionBar.newTab().setText(mFriend.getName()).setTabListener(tabListener);
        mActionBar.addTab(mTab1);

        // Create second Tab
        Tab mTab2 = mActionBar.newTab().setText("Debts").setTabListener(tabListener);
        mActionBar.addTab(mTab2);

        // Add Tabs to ViewPager
        mFragments = new ArrayList<Fragment>();
        mFragments.add(FriendOverviewFragment.newInstance("Friend Details"));
        mFragments.add(DebtHistoryFragment.newInstance("Debt History"));

        // Instantiate adapter and add it to ViewPager
        mTabAdapter = new TabViewAdapter(getSupportFragmentManager(), mFragments);
        mTabView.setAdapter(mTabAdapter);
    }
}

From source file:cmpe.alpha.fitwhiz.sensortag.ViewPagerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(mResourceFragmentPager);

    // Set up the action bar
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ImageView view = (ImageView) findViewById(android.R.id.home);
    view.setPadding(10, 0, 20, 10);// w  w w.j  a  v  a 2s  .c  o  m

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(mResourceIdPager);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int n) {
            // Log.d(TAG, "onPageSelected: " + n);
            actionBar.setSelectedNavigationItem(n);
        }
    });
    // Create the adapter that will return a fragment for each section
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager.setAdapter(mSectionsPagerAdapter);
}

From source file:com.inc.playground.playgroundApp.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    globalVariables = ((GlobalVariables) getApplication());
    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    setPlayGroundActionBar();/*ww w .j  a  v  a  2 s  . c o  m*/
    //set actionBar color
    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primaryColor)));
    actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.secondaryColor)));
    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    //actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    // Specify that we will be displaying tabs in the action bar.
    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
        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 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().setTabListener(this));
    }
    actionBar.getTabAt(0).setIcon(R.drawable.pg_list_view);
    actionBar.getTabAt(1).setIcon(R.drawable.pg_map_view);
    //NavigationDrawer handling (e.g the list from leftside):
    mTitle = mDrawerTitle = getTitle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.menu_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.pg_menu, /* nav drawer icon to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description */
            R.string.drawer_close /* "close drawer" description */
    ) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            getActionBar().setTitle(mTitle);
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            getActionBar().setTitle(mDrawerTitle);
        }
    };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerLayout.closeDrawers();
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // all linear layout from slider menu

    /*Home button */
    LinearLayout ll_Home = (LinearLayout) findViewById(R.id.ll_home);
    ll_Home.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this, MainActivity.class);
            startActivity(iv);
            finish();
        }
    });
    /*Login button */
    LinearLayout ll_Login = (LinearLayout) findViewById(R.id.ll_login);
    ll_Login.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            LinearLayout ll_Login = (LinearLayout) v;
            TextView loginTxt = (TextView) findViewById(R.id.login_txt);
            if (loginTxt.getText().equals("Login")) {
                Intent iv = new Intent(MainActivity.this, Login.class);
                startActivity(iv);
                finish();
            } else if (loginTxt.getText().equals("Logout")) {
                final Dialog alertDialog = new Dialog(MainActivity.this);
                alertDialog.setContentView(R.layout.logout_dilaog);
                alertDialog.setTitle("Logout");
                alertDialog.findViewById(R.id.ok_btn).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
                        SharedPreferences.Editor editor = prefs.edit();
                        editor.clear();
                        editor.commit();
                        ImageView loginImg = (ImageView) findViewById(R.id.login_img);
                        TextView loginTxt = (TextView) findViewById(R.id.login_txt);
                        loginTxt.setText("Login");
                        loginImg.setImageResource(R.drawable.pg_action_lock_open);

                        globalVariables = ((GlobalVariables) getApplication());
                        globalVariables.SetCurrentUser(null);
                        globalVariables.SetUserPictureBitMap(null);
                        globalVariables.SetUsersList(null);
                        globalVariables.SetUsersImagesMap(null);

                        Util.clearCookies(getApplicationContext());

                        Intent iv = new Intent(MainActivity.this, MainActivity.class);
                        startActivity(iv);
                        finish();
                    }
                });

                alertDialog.findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent iv = new Intent(MainActivity.this, MainActivity.class);
                        startActivity(iv);
                        finish();
                    }
                });

                alertDialog.show(); //<-- See This!
            }

        }
    });
    //
    //        /*Setting button*/
    //        LinearLayout ll_Setting = (LinearLayout) findViewById(R.id.ll_settings);
    //        ll_Setting.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                // TODO Auto-generated method stub
    //                // new changes
    //                Intent iv = new Intent(MainActivity.this,
    //                        com.inc.playground.playgroundApp.upLeft3StripesButton.
    //                                SettingsActivity.class);
    //                startActivity(iv);
    //                finish();
    //            }
    //        });

    /*My profile button*/
    LinearLayout ll_my_profile = (LinearLayout) findViewById(R.id.ll_my_profile);
    ll_my_profile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // new changes
            globalVariables = ((GlobalVariables) getApplication());
            User currentUser = globalVariables.GetCurrentUser();
            if ((currentUser == null) || (currentUser != null && currentUser.GetUserId() == null)) {
                Toast.makeText(MainActivity.this, "You are not logged in", Toast.LENGTH_LONG).show();
            } else {

                Intent iv = new Intent(MainActivity.this,
                        com.inc.playground.playgroundApp.upLeft3StripesButton.MyProfile.class);

                //for my profile
                iv.putExtra("name", currentUser.getName());
                iv.putExtra("createdNumOfEvents", currentUser.getCreatedNumOfEvents());
                //pass events
                iv.putExtra("events", currentUser.getEvents());
                iv.putExtra("events_wait4approval", currentUser.getEvents_wait4approval());
                iv.putExtra("events_decline", currentUser.getEvents_decline());

                iv.putExtra("photoUrl", currentUser.getPhotoUrl());
                startActivity(iv);
                //
            }
        }
    });

    LinearLayout ll_aboutUs = (LinearLayout) findViewById(R.id.ll_about);
    ll_aboutUs.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this, AboutUs.class);
            startActivity(iv);
            finish();
        }
    });

}

From source file:org.catnut.ui.PluginsActivity.java

private void injectPager(ActionBar bar, Bundle savedInstanceState) {
    // not show the bar, but not hide, u known what i mean?
    bar.setDisplayHomeAsUpEnabled(false);
    bar.setDisplayShowHomeEnabled(false);
    bar.setDisplayShowTitleEnabled(false);
    setContentView(R.layout.pager);//from w  ww. ja  va2s.c  om

    mIds = getIntent().getIntegerArrayListExtra(PLUGINS);
    if (savedInstanceState == null) {
        mIds.add(0); // add an alt one...
    }
    Collections.shuffle(mIds); // shuffle it :-)
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setPageMargin(10);

    mViewPager.setPageMarginDrawable(new ColorDrawable(getResources().getColor(R.color.tab_selected)));
    mViewPager.setAdapter(new FragmentPagerAdapter(getFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            Fragment fragment;
            switch (mIds.get(position)) {
            case PluginsPrefFragment.ZHIHU:
                fragment = ZhihuItemsFragment.getFragment();
                break;
            case PluginsPrefFragment.FANTASY:
                fragment = FantasyFallFragment.getFragment();
                break;
            default:
                fragment = new PlaceHolderFragment();
                break;
            }
            return fragment;
        }

        @Override
        public int getCount() {
            return mIds.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (mIds.get(position)) {
            case PluginsPrefFragment.ZHIHU:
                return getString(R.string.read_zhihu);
            case PluginsPrefFragment.FANTASY:
                return getString(R.string.fantasy);
            default:
                return "more plugins...";
            }
        }
    });
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });
    for (int i = 0; i < mViewPager.getAdapter().getCount(); i++) {
        bar.addTab(bar.newTab().setText(mViewPager.getAdapter().getPageTitle(i)).setTabListener(this));
    }
}