fragment - '在导航返回'与后按钮的方式不同
我正在编写Android应用程序,使用片段。
有两种主要方法可以向上或向后导航。
首先是在导航栏上使用箭头(标记为图片中的数字1)
第二个使用系统后按钮(标记为数字2)
:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
...
requireActivity().onBackPressedDispatcher.addCallback(this) {
findNavController().navigate(R.id.action_updateFragment_to_listFragment)
...
}
它可以正常工作,但仅适用于系统返回按钮(2)。
如何通过单击导航栏(1)的背面箭头引起的动作?
谢谢!!!
I'm writing android app, using fragments.
There are two main ways to navigate up or back.
The first is to use the arrow on the navigation bar (marked with the number 1 in the picture)
The second use the system back button (marked with the number 2)
I wrote:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
...
requireActivity().onBackPressedDispatcher.addCallback(this) {
findNavController().navigate(R.id.action_updateFragment_to_listFragment)
...
}
and it works just fine, but only for system back button(2).
How can I override action caused by click on the back arrow from navigation bar(1)?
thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我知道了。
我希望这篇文章将来会帮助某人。
Ok, I've got this.
I hope this post will help someone in the future.