作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
来自 docs ,我看到你可以像这样嵌套导航图:
NavHost(navController, startDestination = "home") {
...
// Navigating to the graph via its route ('login') automatically
// navigates to the graph's start destination - 'username'
// therefore encapsulating the graph's internal routing logic
navigation(startDestination = "username", route = "login") {
composable("username") { ... }
composable("password") { ... }
composable("registration") { ... }
}
...
}
我想知道,如何在 route 传递一个参数,并将其提供给导航图中的所有可组合项?
navigation(
// I'd like to grab this parameter
route = "dashboard?classId={classId}",
startDestination = Route.ScreenOne.route) {
composable(Route.ScreenOne.route) {
// And then pass the parameter here, or to any composable below
ScreenOne(classId)
}
composable(Route.ScreenTwo.route) {
ScreenTwo()
}
composable(Route.ScreenThree.route) {
ScreenThree()
}
}
我基本上是在尝试避免在每个可组合路线上单独设置 classId 导航参数。我没有看到将参数列表传递给
navigation()
的方法就像你可以在
composable()
.
最佳答案
您可以从子可组合项访问图形参数:
navController.getBackStackEntry("dashboard?classId={classId}").arguments?.getString("classId")
关于android - 将参数传递给 Jetpack Compose 中的嵌套导航图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70086094/
我有三个 Controller 。让我们依次说 Controller A、B 和 C。 Controller A 中的导航标题颜色为红色。 Controller B 为蓝色, Controller C
我有一个导航图,它使用此 fragment 作为主 Activity XML 中的主页。 我有一个带有菜单的抽屉布局,当我单击抽屉导航按钮时,我无法使导航正常工作(它在主 fragm
我是一名优秀的程序员,十分优秀!