1.添加依赖
implementation 'com.android.support:design:26.0.0'
2.在项目路径新建menu目录。src/res/menu
3.在项目路径新建bottom_navigation.xml
src/res/menu/bottom_navigation.xml
4.编辑bottom_navigation.xml
android:icon="@drawable/ic_launcher"自己从网上找图片放进去。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/navigation_bottom_1"
android:title="主页"
android:icon="@drawable/ic_launcher"
app:showAsAction="always" />
<item
android:id="@+id/navigation_bottom_2"
android:title="选项"
android:icon="@drawable/ic_launcher"
app:showAsAction="always" />
<item
android:id="@+id/navigation_bottom_3"
android:title="我的"
android:icon="@drawable/ic_launcher"
app:showAsAction="always" />
</menu>
5.编辑activity_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/bottom_navigation"
>
</android.support.design.widget.BottomNavigationView>
</LinearLayout>