Basic properties
Setactivecolor//Select the font color for itemSetinactivecolor//the color in item is not selectedSetbarbackgroundcolor//Background Colorsetmode (bottomnavigationbar.mode_fixed)//fill mode, unselected item displays text, no shift animationsetmode (bottomnavigationbar.mode_shifting)//shift mode, the unselected item does not display text, and the selected text is displayedSetbackgroundstyle (bottomnavigationbar.background_style_static)//no water ripple effect when clickedSetbackgroundstyle (bottomnavigationbar.background_style_ripple)//when clicked, there is a ripple effect, that is, the background color of the navigation bar is the color of the item that you set in the selected state .AddItem (NewBottomnavigationitem (R.mipmap.ic_launcher_round, mtitles[0])//Add a Bottomnavigationitem subkey, set the icon and textSetinactiveicon (contextcompat.getdrawable ( This, R.mipmap.ic_launcher))//Add a Change icon when selectedSetfirstselectedposition (0)//The item labeled 0 is selected by defaultSetbadgeitem ()//Add Badgeitem Taginitialise ()//drawn, to be placed at the end of the set
Settabselectedlistener Listener
Bottomnavigationbar.settabselectedlistener (NewBottomnavigationbar.ontabselectedlistener () {@Override Public voidOntabselected (intposition) { //triggered when a selected state is obtainedToast.maketext (mainactivity. This, "currently selected" +position,toast.length_short). Show (); } @Override Public voidOntabunselected (intposition) { //triggered when the loss of focus is not selectedToast.maketext (mainactivity. This,position+ "lost Focus", Toast.length_short). Show (); } @Override Public voidOntabreselected (intposition) { //can't trigger, I'm a hen too }});Badgeitem Mark 1. Pentagram Mark
New Shapebadgeitem () // Background Color // the location defaults to the top right . Setanimationduration// animation duration . sethideonselect (false)// True disappears when status is selected, unchecked show // Hide
2. Text Markers
New Textbadgeitem () . Setborderwidth (4)// text Size . setgravity (gravity.top)// the location defaults to top right . Setbackgroundcolorresource (r.color.coloraccent)// background color . Setanimationduration// animation time . SetText ("3") . Sethideonselect ( false) // true to disappear when state is selected, unchecked to show again . Show ();
Official All.gif
View Source
Android Bottomnavigationbar navigation Bar