Imitate the bottom navigation bar of Zhihu

Here’s the original version:

Function introduction:

1> Create NavigationBottom menu file in res/menu folder as follows:

         
            
            

            

            

            

        
Copy the code
Note:
1) the default internal insetLeft insetRight, insetTop, insetBottom default is 12 dp. App :nb_insetLeft, app:nb_insetTop, app:nb_insetRight, nb_insetBottom app:nb_insetLeft, app:nb_insetTop, app:nb_insetRight, nb_insetBottom The default value is 12DP. This way, when you set the icon and find that there are individual ICONS and other different sizes, you can use the above four attributes to fine-tune the size of the specified icon to achieve the overall purpose of consistency. 2) If the sum of insetLeft and insetRight is greater than the width of a Tab, an exception will be raised: IllegalArgumentException (XML attribute of "app:insetLeft" or "app:insetRight" is too large!) 3) The same goes for insetTop and insetBottomCopy the code

2> Use in XML files:

         
Copy the code
Note:
The layout_width in the MyNavigationBottom tag is ideally match_parent. When the size is specific, an exception is thrown:  IllegalArgumentException (NavigationBottom's width must be match_parent,which couldn't less than screenSize) When it is wrAP_content, internal onMeasure() automatically adjusts it to match_parent. Do not set layout_height to match_parent. Set layout_height to a specific value, such as 48dpCopy the code

Run screenshot:

Write at the end: