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

本文介绍了Android设计中的BottomNavigationView,这是一个符合Material Design风格的底部导航栏。内容包括如何在APP级别gradle中引入,使用Android Studio的模板快速配置,以及BottomNavigationView的源码解析,如BottomNavigationMenuView、BottomNavigationItemView和BottomNavigationPresenter的工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

源码中的介绍:

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

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


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

  • BottomNavigationView源码解读





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

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

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

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





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值