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