nav布局 <fragment android:id="@+id/zhuFragment" android:name="com.example.mym416yk.fragment.ZhuFragment" android:label="fragment_zhu" tools:layout="@layout/fragment_zhu" > <action android:id="@+id/action_zhuFragment_to_fenFragment" app:destination="@id/fenFragment" /> </fragment> <fragment android:id="@+id/fenFragment" android:name="com.example.mym416yk.fragment.FenFragment" android:label="fragment_fen" tools:layout="@layout/fragment_fen" > <action android:id="@+id/action_fenFragment_to_gouFragment" app:destination="@id/gouFragment" /> </fragment> <fragment android:id="@+id/gouFragment" android:name="com.example.mym416yk.fragment.GouFragment" android:label="fragment_gou" tools:layout="@layout/fragment_gou" > <action android:id="@+id/action_gouFragment_to_woFragment2" app:destination="@id/woFragment2" /> </fragment> <fragment android:id="@+id/woFragment2" android:name="com.example.mym416yk.fragment.WoFragment" android:label="fragment_wo" tools:layout="@layout/fragment_wo" />
meun——item
<item android:id="@+id/zhuFragment" android:title="首页" android:icon="@drawable/shou"></item> <item android:id="@+id/fenFragment" android:title="视频" android:icon="@drawable/shou"></item> <item android:id="@+id/gouFragment" android:title="社区" android:icon="@drawable/gowuche"></item> <item android:id="@+id/woFragment2" android:title="我的" android:icon="@drawable/ic_launcher_foreground"></item>
主页
val navHostFragment = supportFragmentManager.findFragmentById(R.id.fcon) as NavHostFragment val navController = navHostFragment.navController val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bnav) as BottomNavigationView bottomNavigationView.setupWithNavController(navController)