我想以编程方式检索嵌套图以更改startDestination
。
适用于navHost的
val navHostFragment = appNavFragment as NavHostFragment
val inflater = navHostFragment.navController.navInflater
val graph = inflater.inflate(R.navigation.nav_app)
graph.startDestination = if(sth) startDestination1 else startDestination2
val navController = navHostFragment.navController
navController.graph = graph
我想对嵌套图执行相同的操作,但是我不知道如何以编程方式检索它。
答案 0 :(得分:0)
我找到了解决方案,对于我需要使用findNode
val node = graph.findNode(R.id.nav_main)
(node as NavGraph).startDestination = R.id.onboarding_dest