我在我的应用程序中使用Jetpack导航,我现在遇到了一个我不完全理解的情况。我有一个片段CouponFragment,它应该在多个地方使用(通过静态xml标记在其他片段中,在没有连接到navGraph的bottomSHeetDialog中)。我需要这个片段才能导航到WebviewFragment,它是navGraph中的一个目的地。我为CouponFragment添加了导航条目
在最简单的情况下(在另一个导航连接片段中的CouponFragment),解决方案非常直接,我在包含CouponFragment的片段中添加了一个操作,例如:
<fragment
android:id="@+id/navigation_results"
android:name="ResultsFragment"
tools:layout="@layout/fragment_results">
<action
android:id="@+id/action_webview"
app:destination="@id/navigation_webview" />
</fragment>这个很管用。真正的问题是当我试图从CouponFragment导航时,它位于BottomSheetFragmentDialog中。我尝试将一个操作添加到导航连接的片段中,该片段调用对话框:
<fragment
android:id="@+id/navigation_profile"
android:name="ProfileFragment"
android:label="@string/title_profile"
tools:layout="@layout/fragment_profile">
<action
android:id="@+id/action_webview"
app:destination="@id/navigation_webview" />
</fragment>但这导致了这种感觉:
java.lang.IllegalArgumentException: Navigation action/destination package.name:id/action_webview cannot be found from the current destination Destination(package.name:id/navigation_webview) class=WebViewFragment奇怪的是,因为它看起来像是在目标片段上搜索动作。我尝试将action_webview添加到navigation_webview中
只是为了看看会发生什么却什么都不做。没有打印日志。
有人能给出一个如何处理这个问题的提示吗?
发布于 2020-10-29 10:11:58
我将开始解开主要问题,因为细节非常模糊,并在必要时进行编辑。
要从non_navigation片段导航:
https://developer.android.com/guide/navigation/navigation-deep-link
例如:
嵌套Non-Navigation-FragmentY
的
要从FragmentY导航到FragmentB,只需从MainNavigationHostFragment加载NavController并设置为目标NavController
https://stackoverflow.com/questions/64588100
复制相似问题