使用导航组件时如何覆盖工具栏中的后退按钮行为

I have three fragments A,B and C , I can navigate from A to B and also from A to C. when I navigate from A to B using navigation component I see a back arrow in the AppBar which navigates back to A. I want to show a dialog like Image below when that arrow is pressed. but I don't want to see that dialog when I navigate back from C to A. is there any way to have this behavior in only one fragment? I tried to use requireActivity().onBackPressedDispatcher.addCallback but it only works for back button. Thanks enter image description here

评论
上个路口
上个路口

您的问题还不是很清楚..但是您是否尝试覆盖按下后退按钮的方法以显示对话框。 但是,如果可以,您应该编辑您的问题以充分说明您想要什么

点赞
评论