一、基础使用流程
1. 添加依赖
在 build.gradle中添加 Material Design 库依赖:
dependencies {
implementation 'com.google.android.material:material:1.11.0' // 使用最新版本
}
2. 布局文件 (activity_main.xml)
<RelativeLayout 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">
<!-- Fragment 容器 -->
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/bottom_navigation" />
<!-- 底部导航栏 -->
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="@menu/bottom_nav_menu" />
</RelativeLayout>
3. 定义菜单资源 (res/menu/bottom_nav_menu.xml)
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/nav_home"
android:icon="@drawable/ic_home"
android:title="首页" />
<item
android:id="@+id/nav_search"
android:icon="@drawable/ic_search"
android:title="搜索" />
<item
android:id="@+id/nav_profile"
android:icon="@drawable/ic_profile"
android

最低0.47元/天 解锁文章
3万+

被折叠的 条评论
为什么被折叠?



