以编程方式在使用导航组件设置的导航抽屉中导航
谁能帮我解决这个问题吗?
中使用导航组件设置
我目前有一个导航抽屉,在我的 MainActivity
代码
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
navController = navHostFragment.navController
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.fragment1,
R.id.fragment2,
R.id.fragment3
), layoutDrawer
)
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration)
navView.setupWithNavController(navController)
: 我想要的:
我想以编程方式导航到特定片段,而不使用 R.id.action
因为我将在 MainActivity
中编写代码,它不属于我的 NavGraph
类似的东西
navController.navigate(R.id.fragment3)
会很好
Can anyone help me out with this?
I currently have a Navigation Drawer that is setup with Navigation Component in my MainActivity
Code:
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
navController = navHostFragment.navController
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.fragment1,
R.id.fragment2,
R.id.fragment3
), layoutDrawer
)
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration)
navView.setupWithNavController(navController)
What I want:
I want to programmatically navigate to a specific fragment without the use of R.id.action
since I will be writing the code in the MainActivity
which is not part of my NavGraph
Something like
navController.navigate(R.id.fragment3)
would be nice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论