【问题标题】:How to hide the bottom navigation bar in certain fragments?如何在某些片段中隐藏底部导航栏?
【发布时间】:2019-06-05 13:08:04
【问题描述】:

我有一个带有 navGraph 的活动和一个带有 2 个菜单项的底部导航栏。 我的问题是My Bottom Navigation Bar到处出现,detailFragment、aboutFragment、signInFragment等等。


        val navController = this.findNavController(R.id.myNavHostFragment)

        val appBarConfiguration = AppBarConfiguration.Builder(
            R.id.contactsFragment,
            R.id.profileFragment
        ).build()

        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration)

        val navView: BottomNavigationView = findViewById(R.id.nav_view)
        NavigationUI.setupWithNavController(navView, navController)


我如何限制它只显示在我的菜单项上的 2 个片段上?

我就是这样解决的

    navController.addOnDestinationChangedListener{ _, nd: NavDestination, _->
        if(nd.id == R.id.contactsFragment || nd.id == R.id.profileFragment){
            navView.visibility = View.VISIBLE
        }else{
            navView.visibility = View.GONE
        }

【问题讨论】:

  • 感谢您在解决方案中进行编辑,为我节省了一些时间!
  • 不客气@SlowDeep,快乐编码

标签: kotlin android-jetpack android-bottomappbar android-jetpack-navigation


【解决方案1】:

对于应该可见的片段

navView.visibility = View.VISIBLE

不应该看到的地方

navView.visibility = View.GONE

【讨论】:

  • 工作,谢谢,最大的问题是找到片段来设置可见性,最终使用了监听器
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-03
相关资源
最近更新 更多