android - 如何使用导航组件保持对话框打开?

标签 android android-architecture-navigation

我正在尝试从 导航对话 fragment 带有导航组件。我面临导航后对话框自动弹出的问题,因为它实现了 androidx.navigation.FloatingWindow 接口(interface)(文档链接 - https://developer.android.com/guide/navigation/navigation-navigate)。
所以,我想保持底层对话框打开。实现这一目标的最佳选择是什么?
我的导航图:

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/return_order_dialog_nested_nav_graph"
    app:startDestination="@id/returnOrderBottomDialog">

<dialog
    android:id="@+id/returnOrderBottomDialog"
    android:name="ru.dpd.features.returnOrder.ReturnOrderBottomDialog"
    android:label="ReturnOrderBottomDialog"
    tools:layout="@layout/dialog_bottom_return_order">
    <argument
        android:name="orderId"
        app:argType="string" />
    <action
        android:id="@+id/action_returnOrderBottomDialog_to_returnOrderDepartmentMapFragment"
        app:destination="@id/returnOrderDepartmentMapFragment" />
</dialog>

<fragment
    android:id="@+id/returnOrderDepartmentMapFragment"
    android:name="ru.dpd.features.returnOrder.tabs.map.ReturnOrderDepartmentMapFragment"
    android:label="ReturnOrderDepartmentMapFragment"
    tools:layout="@layout/fragment_departments_map">
    <argument
        android:name="orderId"
        app:argType="string" />
    <argument android:name="cityId" />
</fragment>

</navigation>
Visual graph repesentation

最佳答案

没有官方解决方案,这是一种解决方法。我尝试使用容器 fragment 作为后台堆栈中的条目/节点。
实际上,当它出现在用户面前时容器启动对话框(在导航或弹出窗口中)
容器 fragment 没有 View 。它在 onCreateView 中启动对话框.所有对话参数 (orderId,..)必须传递给容器 fragment ,然后手动传递给对话框。

class MyDialogContainerFragment : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        // launch the dialog
        findNavController(this).navigate(....)

        return null
    }
}

关于android - 如何使用导航组件保持对话框打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67498750/

相关文章:

java - ionic 无法构建android

android - Intent 过滤器 url 在标签后被截断

android gradle 错误 :Unable to find module with Gradle path ':libs' (needed by module 'app' . )

android - 如何在Android上实现流畅的 fragment 交易动画

android - 如何保持 fragment View 状态?

deep-linking - Jetpack 撰写 : Bottom bar navigation not responding after deep-linking

android - 无法从 Moto 360 读取心率传感器 - Android Wear

android - 导航到 fragment 时传递安全参数

android - 导航库充气器为数据类抛出 ClassNotFoundException

android - 找不到androidx.navigation :safe-args-gradle-plugin:1. 0.0-alpha01