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.marshalchen.common.demoofui.quickreturnlistview.QuickReturnListViewActivity.java

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

    PagerAdapter adapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) {
        @Override/*from  w  w  w. j a  va  2  s.c o m*/
        public Fragment getItem(int position) {
            switch (position) {
            case 0:
                return new DefaultFragment();
            case 1:
                return new AnimationFragment();
            case 2:
                return new BottomFragment();
            }
            return null;
        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
            case 0:
                return "default_fragment";
            case 1:
                return "animation_fragment";
            case 2:
                return "footer_fragment";
            }
            return null;
        }
    };

    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(adapter);
    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    mPager.setPageMargin(20);

    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    for (int position = 0; position < adapter.getCount(); position++) {
        getActionBar()
                .addTab(getActionBar().newTab().setText(adapter.getPageTitle(position)).setTabListener(this));
    }

    getActionBar().setDisplayShowHomeEnabled(false);
    getActionBar().setDisplayShowTitleEnabled(false);
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_frienddetails);
    mDB = new DatabaseHandler(this);
    getActionBar().setDisplayShowTitleEnabled(false);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    mFriend = (Friend) getIntent().getExtras().get(FRIEND);

    mOverViewFrag = new FriendOverviewFragment();
    mDebtHistoryFrag = new FriendHistoryFragment();

    if (findViewById(R.id.activity_frienddetails_tabView) != null) {
        mTabView = (ViewPager) findViewById(R.id.activity_frienddetails_tabView);
        mPageAdapter = new TabPagerAdapter(getFragmentManager(),
                new FriendFragment[] { mOverViewFrag, mDebtHistoryFrag });
        getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        mTabView.setAdapter(mPageAdapter);
        mTabView.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

            @Override//from ww w  .j  av  a2  s. com
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                // Find the ViewPager Position
                getActionBar().setSelectedNavigationItem(position);
                mTabView.setCurrentItem(position, true);
            }
        });
        // 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) {
            }

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

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

        // Create tabs
        getActionBar().addTab(getActionBar().newTab().setText(mFriend.getName()).setTabListener(tabListener));
        getActionBar().addTab(
                getActionBar().newTab().setText(getString(R.string.history)).setTabListener(tabListener));
    } else {
        // Just show the fragments otherwise
        getFragmentManager().beginTransaction().replace(R.id.activity_frienddetails_frame1, mOverViewFrag)
                .commit();
        getFragmentManager().beginTransaction().replace(R.id.activity_frienddetails_frame2, mDebtHistoryFrag)
                .commit();
    }
}

From source file:com.example.swipeuiforupclose.MainActivity.java

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

    // 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./*  www  .j  ava  2  s. c o m*/
    actionBar.setHomeButtonEnabled(false);
    actionBar.setBackgroundDrawable(new ColorDrawable(0xFF46304e));
    actionBar.setStackedBackgroundDrawable(new ColorDrawable(0xFF573d5d));
    actionBar.setTitle("My Profile");

    // Specify that we will be displaying tabs in the action bar.
    //actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    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));
    }
}

From source file:com.xenon.greenup.MainActivity.java

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // 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 the stacked background otherwise we get the gross dark gray color under the icon
    BitmapDrawable background = (BitmapDrawable) getResources().getDrawable(R.drawable.bottom_menu);
    background.setTileModeXY(TileMode.REPEAT, TileMode.MIRROR);
    actionBar.setStackedBackgroundDrawable(background);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setIcon(R.drawable.bottom_menu);

    _ViewPager = (ViewPager) findViewById(R.id.pager);
    mTabsAdapter = new TabsAdapter(this, _ViewPager);

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < 3; 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.Tab tabToAdd = actionBar.newTab();
        if (i == 0)
            //Set the home page as active since we'll start there:
            tabToAdd.setIcon(getActiveIcon(i));
        else/*from w ww .  j  ava2 s  .  co  m*/
            tabToAdd.setIcon(getRegularIcon(i));
        mTabsAdapter.addTab(tabToAdd);

    }

    //Setting the display to custom will push the action bar to the top
    //which gives us more real estate
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.show();
    Log.i("visible", "" + _ViewPager.VISIBLE);

}

From source file:com.larswerkman.quickreturnlistview.MainActivity.java

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

    PagerAdapter adapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) {
        @Override/*from w w  w  .  ja  v  a2s . c  om*/
        public Fragment getItem(int position) {
            switch (position) {
            case 0:
                return new DefaultFragment();
            case 1:
                return new AnimationFragment();
            case 2:
                return new BottomFragment();
            }
            return null;
        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
            case 0:
                return getString(R.string.default_fragment);
            case 1:
                return getString(R.string.animation_fragment);
            case 2:
                return getString(R.string.footer_fragment);
            }
            return null;
        }
    };

    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(adapter);
    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    mPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.page_margin));

    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    for (int position = 0; position < adapter.getCount(); position++) {
        getActionBar()
                .addTab(getActionBar().newTab().setText(adapter.getPageTitle(position)).setTabListener(this));
    }

    getActionBar().setDisplayShowHomeEnabled(false);
    getActionBar().setDisplayShowTitleEnabled(false);
}

From source file:edu.csh.coursebrowser.SectionInfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_section_info);
    Bundle args = this.getIntent().getExtras();

    this.args = args.getString("args");
    this.setTitle(args.getString("title"));
    Log.v("Sections", args.getString("args"));

    // Set up the action bar to show tabs.
    final ActionBar actionBar = getActionBar();
    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("All").setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText("Non-Full").setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText("Full").setTabListener(this));

}

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  w w w  .j  av  a 2s. 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.example.kaow.caltest.UserInfo.java

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

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

    final ActionBar actionBar = getActionBar();
    // Specify that the Home button should show an "Up" caret, indicating that touching the
    // button will take the user one step up in the application's hierarchy.
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from w  w  w .  ja v a2s.c  o  m
        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 < uInfoTitles.length; i++) {
        actionBar.addTab(actionBar.newTab().setText(uInfoTitles[i]).setTabListener(this));

    }
}

From source file:tcc.blindguide.PrincipalActivity.java

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

    // 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.//from  w ww  .j  a v  a  2s  . co m
    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.principal_activity_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));
    }

    ApplicationManager.Initialize(this.getSupportFragmentManager());

}

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/*w w  w  .j  a va  2 s .c  om*/
        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));
}