如何使用导航组件切换到不同后堆栈中的其他片段?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用导航组件切换到不同后堆栈中的其他片段?相关的知识,希望对你有一定的参考价值。

我有3个底部导航选项卡,称为Home, Dashboard, Profile

  • Home中,我有Fragment1Fragment2
  • Dashboard中,我有Fragment3Fragment4
  • [在Profile中,我有MyProfileEditProfile

现在,在Fragment2中,按钮changeAvatar可以打开堆栈EditProfile中的Profile。因为EditProfile应该在选项卡Profile中,所以如果我不想将EditProfile包含在navGraphHome中,该如何实现该行为?

答案

尝试使用深层链接

导航图。

<fragment
    android:id="@+id/editProfileFragment"
 >

...
    <deepLink
        android:id="@+id/deepLink"
        app:uri="yourapp://edit/prfile" />
...
</fragment>

在片段中。

findNavController().navigate(Uri.parse("yourapp://edit/prfile"))

以上是关于如何使用导航组件切换到不同后堆栈中的其他片段?的主要内容,如果未能解决你的问题,请参考以下文章