我在活动中动态创建了起始目的地,但由于无法引用导航主机的ID,因此无法分段创建。
在活动中我这样做:
val navHostFragment = nav_host_fragment as NavHostFragment
val navController = navHostFragment.navController
val navInflater = navController.navInflater
val graph = navInflater.inflate(R.navigation.nav_main)
graph.startDestination = R.id.detail_fragment
val navShipmentId = NavArgument.Builder().setDefaultValue(shipmentId).build()
navHostFragment.navController.graph = graph