源码中的介绍:

Represents a standard bottom navigation bar for application. It is an implementation of
* <a href="https://material.google.com/components/bottom-navigation.html">material design bottom
* navigation</a>.

代表应用程序的标准底部导航栏,一个满足material design风格的底部导航控件。

以下基于AS 3.1.2 版本

  • 一、用法

1、  在APP级别gradle中加入这句话

implementation 'com.android.support:design:27.1.1'

或者File->Project Structure

Android Design 包常用控件知识——BottomNavigationView

导入后即可在XML中使用BottomNavigationView,还有更简单的方法,如下

Android Design 包常用控件知识——BottomNavigationView

直接使用Android Studio Template中集成好的模板,就可以想怎么改就怎么改了。

  • BottomNavigationView源码解读

Android Design 包常用控件知识——BottomNavigationView

Android Design 包常用控件知识——BottomNavigationView

Android Design 包常用控件知识——BottomNavigationView

Android Design 包常用控件知识——BottomNavigationView

Android Design 包常用控件知识——BottomNavigationView

BottomNavigationMenuView这个类是实际的init menu类,这就是一个自定义view。里面通过buildMenuView()方法创建子菜单view,updateMenuView()刷新子菜单状态。

BottomNavigationItemView这个类就是要实例化的单个子菜单view了,里面有设定style的方法,还有选中状态更改的方法。

BottomNavigationPresenter这个类可以当成MVP中的P,是MenuPresenter的实现,虽然大多都没有真正的实现。

MenuInflater,xml文件映射object转换类。





相关文章: