Android 底部导航停留在屏幕的底部,在应用程序的顶层视图之间提供导航。这是在向后兼容的设计支持库中引入的。当应用程序有三到五个顶级导航时,应该使用底部导航。本文将介绍底部导航的基础知识,并将其与 Fragment相结合。我们还将学习如何通过通过 HTTP 调用获取 JSON 来加载第一个带有网格数据的片段(使用 RecyclerView)。
底部导航
使用 Bottom Navigationview 组件可以轻松添加底部导航。您必须使用约束关系或相对关系属性,使它出现在屏幕底部。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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">
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:itemBackground="@color/bgBottomNavigation"
android:foreground="?attr/selectableItemBackground"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:menu="@menu/navigation" />
</android.support.design.widget.CoordinatorLayout>