Android interface Programming--Using the Activity Bar (ActionBar)--For tab navigation

Source: Internet
Author: User

Using Actionbar with fragment for navigation

1, call ActionBar's Setnavigationmodel (actionbar.navigation_mode_tabs) settings using TABS navigation

2, call Actionbar's AddTab () To Add multiple tab tabs

################ #承载Fragment的Activity需要实现implements Firstfragment. Onfragmentinteractionlistener This interface, otherwise the error ############## #第二次碰到这个问题了

Code: Contains the original implementation of the Actionbar Display view component (also need to look at some methods, details)

1  Packagecom.example.administrator.myapplication;2 3 ImportAndroid.net.Uri;4 Importandroid.support.v4.app.Fragment;5 Importandroid.support.v4.app.FragmentTransaction;6 ImportAndroid.support.v4.view.MenuItemCompat;7 ImportAndroid.support.v7.app.ActionBar;8 Importandroid.support.v7.app.AppCompatActivity;9 ImportAndroid.os.Bundle;Ten ImportAndroid.view.Menu; One ImportAndroid.view.MenuInflater; A  - Importlayout. firstfragment; -  the  Public classMainactivityextendsAppcompatactivityImplementsFirstfragment.onfragmentinteractionlistener, Actionbar.tablistener { -  - @Override -     protected voidonCreate (Bundle savedinstancestate) { +         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); +  A         FinalActionBar ActionBar =Getsupportactionbar (); at Actionbar.setnavigationmode (actionbar.navigation_mode_tabs); -         //Add 3 tags in turn -Actionbar.addtab (Actionbar.newtab (). SetText ("First"). Settablistener ( This)); -Actionbar.addtab (Actionbar.newtab (). SetText ("Second"). Settablistener ( This)); -Actionbar.addtab (Actionbar.newtab (). SetText ("Third"). Settablistener ( This)); -  in  -     } to  + @Override -      Public BooleanOncreateoptionsmenu (Menu menu) { theMenuinflater Inflater =NewMenuinflater ( This); * inflater.inflate (r.menu.menu_main,menu); $ menuitemcompat.setshowasaction (Menu.finditem (R.id.search), menuitemcompat.show_as_action_always);Panax Notoginseng menuitemcompat.setshowasaction (Menu.finditem (r.id.progess), menuitemcompat.show_as_action_always); -         return Super. Oncreateoptionsmenu (menu); the  +  A     } the  + @Override -      Public voidontabselected (Actionbar.tab Tab, fragmenttransaction ft) { $Fragment Fragment =Newfirstfragment (); $Bundle args =NewBundle (); -Args.putint ("Zhang", tab.getposition () +1); - fragment.setarguments (args); the  -Android.app.FragmentTransaction FT1 =Getfragmentmanager (). BeginTransaction ();Wuyi Ft.replace (r.id.container,fragment); the         //ft.commit ();//This code does not comment out will save ################################################################################## ########################## -     } Wu  - @Override About      Public voidontabunselected (Actionbar.tab Tab, fragmenttransaction ft) { $  -     } -  - @Override A      Public voidontabreselected (Actionbar.tab Tab, fragmenttransaction ft) { +  the     } -  $ @Override the      Public voidonfragmentinteraction (Uri uri) { the  the     } the}

Android interface Programming--Using the Activity Bar (ActionBar)--For tab navigation

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.