在其他片段中显示的底部导航

时间:2020-05-28 16:08:35

标签: java android android-fragments android-jetpack android-jetpack-navigation

我将很高兴为此获得最终帮助。我有一个活动申请。片段之一也是导航至其他片段的nav_host(例如nav_host2),以进行底部导航。

我想使用深层链接从nav_host 2中的from片段退出到nav_host1,但是请注意nav_host2的底部导航显示在nav_host1上,我不想这样做,如下图所示。

Sign-in fragment in nav_host1

即使它为空,如何在不显示底部导航的情况下退出nav_host2

1 个答案:

答案 0 :(得分:0)

使用addOnDestinationChangedListener并相对于destinationId隐藏和显示bottomNavigation

private val AUTH_NAV_GRAPH = arrayOf(
    R.id.destination_splash,
    R.id.destination_login,
    R.id.destination_register,
    R.id.destination_forgetpassword
)



val navController = findNavController(this,R.id.nav_host_fragment)// this maybe change
navController.addOnDestinationChangedListener { controller, destination, arguments ->
   if(destination.id in AUTH_NAV_GRAPH) {
       bottomNavigation?.visibility=View.GONE

   } else {
       bottomNavigation?.visibility=View.VISIBLE
   }
}

其中AUTH_NAV_GRAPH就像没有bottomNavigation的片段