使用嵌套片段时底部导航栏消失

Potehin Ruslan

我有一个Activity类,它的底部导航栏是3个(Home,Notification,Dashboard)片段,以及Home片段中还有1个片段(UpMenuFragment)。问题是,当我创建UpMenuFragment时,底部栏消失了

MainActivity.kt

    setContentView(R.layout.activity_main)

    val navView: BottomNavigationView = findViewById(R.id.nav_view)

    val navController = findNavController(R.id.nav_host_fragment)
    val appBarConfiguration = AppBarConfiguration(
        setOf(
            R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications
        )
    )
    setupActionBarWithNavController(navController, appBarConfiguration)
    navView.setupWithNavController(navController)

activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="?attr/actionBarSize"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/nav_view"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="0dp"
            android:layout_marginStart="0dp"
            android:background="?android:attr/windowBackground"
            android:duplicateParentState="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:menu="@menu/bottom_nav_menu" />

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/main_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintBottom_toTopOf="@id/nav_view"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

            <fragment
            android:id="@+id/nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:defaultNavHost="true"
            app:layout_constraintBottom_toTopOf="@+id/nav_view"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:navGraph="@navigation/mobile_navigation" />

        </androidx.constraintlayout.widget.ConstraintLayout>

HomeFragment.kt

    val upMenuFragment = UpMenuFragment.newInstance()
    childFragmentManager.beginTransaction().add(R.id.home_up_menu_container, 
    upMenuFragment).commit()

fragment_home.xml

         <?xml version="1.0" encoding="utf-8"?>

         <androidx.constraintlayout.widget.ConstraintLayout
          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">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/home_up_menu_container"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
       </androidx.constraintlayout.widget.ConstraintLayout>

所以有什么问题?

Potehin Ruslan

问题是我正在返回片段中的新视图,而不是 return binding.root

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用底部导航栏管理片段

使用底部导航栏防止片段刷新

带片段的底部导航栏

使用片段通过底部导航栏关闭应用

使用底部栏和片段进行完美的导航

当片段加载闪烁时,使用导航组件进行底部导航

停止刷新底部导航栏片段

如何使用导航组件库从底部导航更改片段更改上的工具栏图标?

使用图像链接时标题导航栏消失

当我使用 jQuery 代码时,我的导航栏消失了

键入搜索栏时消失的导航栏

使用底部导航时删除应用栏的后退按钮 - 颤动

在家庭活动中加载片段时的“幽灵”底部导航栏

片段选择时的Android底部导航栏项的背景颜色变化

加载上一个片段时如何更改底部导航工具栏的图标

修复底部导航栏在其片段包含协调器布局时不断扩展

我的底部导航栏仅在我双击以切换片段时才有效

在Flutter中,当我们导航到新屏幕时,底部导航栏应该会消失

从 Appdelegate 导航时,标签栏和导航栏消失了

从Segue显示视图时,导航栏消失

缩放时如何使导航栏消失?

当我导航回片段时,片段的内容消失了

如果使用导航控制器,如何删除某些片段中的底部导航视图和工具栏?

使用片段实现组成底部导航

如何在片段中隐藏底部导航栏

通过底部导航栏将数据从活动传递到片段

Android Java 底部导航栏片段未显示

带有片段和底部导航栏的Android FloatingActionButton

底部导航栏在片段内部不起作用