未解决的参考:向目的地添加了一些参数后的 NavArgs [英] Unresolved reference: NavArgs after added some arguments to destination

查看:24
本文介绍了未解决的参考:向目的地添加了一些参数后的 NavArgs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个小项目并尝试使用新的导航架构组件.当我尝试向目标添加一些参数时,出现未解析的引用:NavArgs"错误.

I'm working on a small project and trying to use the new navigation architecture components. When i'm trying to add some arguments to a destination i got "Unresolved reference: NavArgs" error.

我遵循了本指南 https://developer.android.com/topic/libraries/architecture/navigation/navigation-pass-data#kotlin并且已经添加了

I followed this guide https://developer.android.com/topic/libraries/architecture/navigation/navigation-pass-data#kotlin and already added

类路径android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha11"

到我的项目 gradle 文件并添加了

to my project gradle file and also added

应用插件:'androidx.navigation.safeargs.kotlin'

到我的应用程序 gradle 文件.

to my app gradle file.

如上面的指南中所见,我想使用 val args: AddKittenFragmentArgs by navArgs() 来获取传递的参数.但是 navArgs() 无法识别.

As seen in the guide above i want to use val args: AddKittenFragmentArgs by navArgs() to get the passed arguments. But navArgs() isn't recognized.

生成的代码中的 NavArgs 也未解析.

Also NavArgs in the generated code isn't resolved.

data class MyFragmentArgs(val argOne: String? = """", val argTwo: String? = """") : NavArgs

推荐答案

根据该页面上的文档:

在使用 -ktx 依赖项时,Kotlin 用户还可以使用 by navArgs() 属性委托来访问参数.

When using the -ktx dependencies, Kotlin users can also use the by navArgs() property delegate to access arguments.

确保您遵循添加组件文档和使用 navigation-fragment-ktx 依赖:

Make sure you are following the Adding Components documentation and using the navigation-fragment-ktx dependency:

implementation "android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha11"

这篇关于未解决的参考:向目的地添加了一些参数后的 NavArgs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆