Use ActionBar to implement Tab navigation (quickly generate Tab style) and actionbartab

Source: Internet
Author: User

Use ActionBar to implement Tab navigation (quickly generate Tab style) and actionbartab

Effect

MainActivity. java implementation:

Package com. rainmer. actionbartab; import android. app. actionBar; import android. app. activity; import android. app. fragmentTransaction; import android. app. actionBar. tab; import android. OS. bundle; import android. widget. toast; public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); ActionBar actionBar = getActionBar (); actionBar. setNavigationMode (ActionBar. NAVIGATION_MODE_TABS); // sets the navigation mode ActionBar. tabListener tabListener = new ActionBar. tabListener () {@ Override public void onTabUnselected (Tab tab, FragmentTransaction ft) {// TODO Auto-generated method stub} @ Override public void onTabSelected (Tab tab, FragmentTransaction ft) {// TODO Auto-generated method stub Toast. makeText (MainActivity. this, "TabSelected" + tab. getPosition (), Toast. LENGTH_SHORT ). show () ;}@ Override public void onTabReselected (Tab tab, FragmentTransaction ft) {// TODO Auto-generated method stub }}; for (int I = 0; I <3; I ++) {Tab tab = actionBar. newTab (); tab. setText ("Tab" + I); tab. setTabListener (tabListener); actionBar. addTab (tab );}}}

For the Style File for Tab Indicator, here's a quick build site: http://jgilfelt.github.io/android-actionbarstylegenerator/

Download the generated zip file and copy it to the project. In the Manifest. xml file, modify the Theme attribute of MainActivity to the corresponding Style name.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.