Bottombar's Android Bottom menu
Introduction : Open Source project Bottombar, implement Android Bottom menu (Common menu, Bottombar implement animation (upper and lower) + Message menu, bottombar+viewpager+fragment achieve cool bottom navigation effect)
Effect:
Development environment: androidstudio2.2.1+gradle-2.14.1
Introduce dependencies:
Compile ' com.android.support:appcompat-v7:23.0.0 ' com.android.support:design:23.+ ' Com.roughike:bottom-bar:1.3.+ '
Part of the code:
Public classMenu1activityextendsappcompatactivity {PrivateBottombar Mbottombar; Privatemainfragment mmainfragment; Privatetwofragment twofragment; Privatethreefragment threefragment; Privatefourfragment fourfragment; Privatefragmenttransaction Transaction; PrivateBottombarbadge unreadmessages; @Overrideprotected voidonCreate (@Nullable Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_menu); Mbottombar= Bottombar.attach ( This, savedinstancestate); //Note: This method should be used before setitemsfrommenu, that is, TAB has not been set before the first call, or will be error. mbottombar.notabletgoodness (); //Add initial fragmentDefaultfragment (NULL= = Mmainfragment? Mmainfragment =mainfragment.newinstance (): mmainfragment); Mbottombar.setitems (R.menu.bottombar_menu); Mbottombar.setonmenutabclicklistener (NewOnmenutabclicklistener () {@Override Public voidOnmenutabselected (@IdResintMenuitemid) { //Click event Menuitemid is the ID of item in R.menu.bottombar_menu Switch(menuitemid) { CaseR.id.bb_menu_main:if(NULL==mmainfragment) {mmainfragment=mainfragment.newinstance (); } replacefragment (Mmainfragment); Break; CaseR.id.bb_menu_chart:if(NULL==twofragment) {twofragment=twofragment.newinstance (); } replacefragment (Twofragment); Unreadmessages.setvisibility (View.gone); Break; CaseR.id.bb_menu_timeline:if(NULL==threefragment) {threefragment=threefragment.newinstance (); } replacefragment (Threefragment); Break; Caser.id.bb_menu_about:if(NULL==fourfragment) {fourfragment=fourfragment.newinstance (); } replacefragment (Fourfragment); Break; default: Break; }} @Override Public voidOnmenutabreselected (@IdResintMenuitemid) { //re-election event, the current has chosen this, and then point the tab. Weibo click on the homepage to refresh the page } }); //When you click on a different button, set a different color//you can set the color in the following three ways.Mbottombar.mapcolorfortab (0, Contextcompat.getcolor ( This, r.color.colorprimary)); Mbottombar.mapcolorfortab (1, Contextcompat.getcolor ( This, r.color.coloraccent)); Mbottombar.mapcolorfortab (2, Contextcompat.getcolor ( This, R.color.green)); Mbottombar.mapcolorfortab (3, Contextcompat.getcolor ( This, R.color.orange)); Setmsg (); } @Overrideprotected voidonsaveinstancestate (Bundle outstate) {Super. Onsaveinstancestate (outstate); //Save the status of Bottombarmbottombar.onsaveinstancestate (outstate); } Private voidreplacefragment (Fragment Fragment) {Fragmentmanager fm=Getsupportfragmentmanager (); Transaction=fm.begintransaction (); Transaction.replace (r.id.main_fragment_layout, fragment);//transaction.hide ();Transaction.commit (); } Private voiddefaultfragment (Fragment Fragment) {Fragmentmanager fm=Getsupportfragmentmanager (); Transaction=fm.begintransaction (); Transaction.add (r.id.main_fragment_layout, fragment); Transaction.commit (); } Private voidsetmsg () {//set a label for tab, the number of the "info" hint//The parameters are: the first few tab; The color of the small circle; the number displayedUnreadmessages = Mbottombar.makebadgefortabat (1, "#FF0000", 13); //set Show or hideunreadmessages.show ();//unreadmessages.hide (); //set the displayed numberUnreadmessages.setcount (4); //set delay time for show/Fade animationsUnreadmessages.setanimationduration (200); //if not point it, it always showsUnreadmessages.setautoshowafterunselection (true); }
SOURCE Download ...
Bottombar's Android Bottom menu