前言
相信大家都有接触到安卓底部导航栏的使用,点击底部不同的图标显示不同的页面实现导航功能。而实现这种功能有很多的方法,有原始线性布局LinearLayout + TextView,按钮组RadioGroup + RadioButton,还有BottomNavigationBar实现。最近学习了BottomNavigationBar使用,写这篇文章记录一下学习过程。
实现如图:
使用之前添加依赖:
implementation 'com.ashokvarma.android:bottom-navigation-bar:2.0.4'
模仿QQ音乐底部导航栏 如图下:
添加布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android