Firebase NavHostFragment在bottomNavigationBar中切换时创建片段
我将Firebase NavHostFragment在bottomNavigationBar中切换时创建片段,firebase,android-fragments,bottomnavigationview,Firebase,Android Fragments,Bottomnavigationview,我将NavHostFragment与BottomNavigationView一起使用,因此每当我通过单击BottomNavigationBar中的图标在片段之间切换时,RecycleServiceAdapter中的片段数据都会被刷新。我不知道这是否正常,但我不希望每次切换时都创建片段。这里的数据库是Firebase/Firestore 在MainActivity.kt中设置NavHostFragment的视图时,会出现一个正常的导航图和一个菜单 private fun setupViews()
NavHostFragment
与BottomNavigationView
一起使用,因此每当我通过单击BottomNavigationBar
中的图标在片段之间切换时,RecycleServiceAdapter中的片段数据都会被刷新。我不知道这是否正常,但我不希望每次切换时都创建片段。这里的数据库是Firebase/Firestore
在MainActivity.kt中设置NavHostFragment
的视图时,会出现一个正常的导航图和一个菜单
private fun setupViews() {
val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragNavHost) as NavHostFragment
navController = navHostFragment.navController
NavigationUI.setupWithNavController(bottomNavView, navHostFragment.navController)
}
活动_main.XML中导航的XML代码
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragNavHost"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:navGraph="@navigation/bottom_nav_graph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="0dp"
app:elevation="0dp"
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/bottom_navigation_menu" />