Android 导航组件 - 无法使用 Extras 和 Safe Args
我正在使用带有 SafeArgs 的 Android 导航组件,并且我想向操作添加共享元素转换。根据 文档, 我应该能够简单地添加一个 Extras 对象作为 navigate()
的参数,所以我尝试这样做:
FragmentNavigator.Extras extras = new FragmentNavigator.Extras.Builder()
.addSharedElement(view, "group_transition")
.build();
NavDirections action = HomeFragmentDirections.actionHomeFragmentToViewFragment(title);
Navigation.findNavController(view).navigate(action, extras);
但是 Android Studio 给出了一个错误,并表示它无法解析的方法。我尝试使用
.navigate(int resId, Bundle args, NavOptions navOptions, Navigator.Extras navigatorExtras) ,
将问题范围缩小到 Navigator.Extras 。 Android Studios 在该参数下给出了一个错误,告诉我:
所需类型:androidx.navigation.Navigator.Extras,
提供的类型:androidx.navigation.fragment.FragmentNavigator.Extras"
我无法弄清楚。 Navigator.Extras
是一个接口,其中 FragmentNavigator.Extras
实现了。除了放弃我想要的转变之外,我还能做些什么吗?
I'm using the Android Navigation component with SafeArgs, and I want to add a shared element transition to an action. According to the documentation, I should be able to simply add an Extras object as a parameter to navigate()
, so I try that:
FragmentNavigator.Extras extras = new FragmentNavigator.Extras.Builder()
.addSharedElement(view, "group_transition")
.build();
NavDirections action = HomeFragmentDirections.actionHomeFragmentToViewFragment(title);
Navigation.findNavController(view).navigate(action, extras);
but Android Studio gives an error, and says it can't resolve the method. I try to use
.navigate(int resId, Bundle args, NavOptions navOptions, Navigator.Extras navigatorExtras)
which narrows the problem down to the Navigator.Extras
. Android Studios puts an error under that argument, telling me:
Required Type: androidx.navigation.Navigator.Extras,
Provided Type: androidx.navigation.fragment.FragmentNavigator.Extras"
Which I can't figure out. Navigator.Extras
is an interface, which FragmentNavigator.Extras
implements. What can I do about this, other than giving up on the transition I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论