Android 如何使用导航架构组件创建一个对话框片段?

Android 如何使用导航架构组件创建一个对话框片段?,android,android-architecture-components,bottom-sheet,android-architecture-navigation,Android,Android Architecture Components,Bottom Sheet,Android Architecture Navigation,我使用BottomSheetDialogFragment来显示一些自定义设置 要求: 当我单击BottomSheetDialogFragment中的任何选项卡时,我将替换该片段并将其添加到backstack,以便当用户单击Backpress或Up操作时,它应该返回BottomSheetDialogFragment的最后一个设置片段 我想使用导航架构组件简化我的事务。 问题: 若我使用导航架构组件从FragmentA导航到BottomSheetDialogFragment,那个么我会收到下面的错误

我使用BottomSheetDialogFragment来显示一些自定义设置

要求:

当我单击BottomSheetDialogFragment中的任何选项卡时,我将替换该片段并将其添加到backstack,以便当用户单击Backpress或Up操作时,它应该返回BottomSheetDialogFragment的最后一个设置片段

我想使用导航架构组件简化我的事务。

问题: 若我使用导航架构组件从FragmentA导航到BottomSheetDialogFragment,那个么我会收到下面的错误

java.lang.IllegalStateException:对话框不能为null 底片

我不知道如何使用导航架构组件实例化BottomSheetDialogFragment,使用下面的代码将不会使用导航架构组件进行维护


在导航组件版本
2.1.0-alpha04
中,
导航图
可以包含
对话框
,作为目的地之一

<?xml version="1.0" encoding="utf-8"?>
<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/main_navigation"
    app:startDestination="@id/startFragment">

    <fragment
        android:id="@+id/loginFragment"
        android:name="com.awesomeproject.android.authentication.login.LoginFragment"
        android:label="Login"
        tools:layout="@layout/login_fragment" />

    <dialog
        android:id="@+id/bottomSheet"
        android:name="com.awesomproject.android.BottomSheetFragment"
        tools:layout="@layout/bottom_sheet_dialog_fragment" />

</navigation>
然后,您可以像对待其他目的地一样对待底页。您可以导航到此目的地或在中传递
safeArgs


干杯

你好@anmol你有没有找到解决办法,因为我正在尝试做sameI尝试以不同的方式做它检查这个演示项目@Hemantsangleok我会检查链接我会构造一个正确的答案并在这里发布@HemantSangleThat将会是greatI尝试过的,但是当我尝试使用导航从对话框导航时,NavController丢失了。您可以共享从对话框到其他片段或对话框的导航代码吗@Boonya有了这个解决方案,底页显示在另一个片段中,而不是当前称为itOh man的片段的阴影,当我在全屏打开时添加带导航的底页时,这很可怕。但是你节省了我的时间。从一个片段更改对话框是很容易的。你知道这个问题的解决方案吗?
<?xml version="1.0" encoding="utf-8"?>
<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/main_navigation"
    app:startDestination="@id/startFragment">

    <fragment
        android:id="@+id/loginFragment"
        android:name="com.awesomeproject.android.authentication.login.LoginFragment"
        android:label="Login"
        tools:layout="@layout/login_fragment" />

    <dialog
        android:id="@+id/bottomSheet"
        android:name="com.awesomproject.android.BottomSheetFragment"
        tools:layout="@layout/bottom_sheet_dialog_fragment" />

</navigation>
class BottomSheetFragment : BottomSheetDialogFragment() {
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View =
            inflater.inflate(R.layout.bottom_sheet_dialog_fragment, container, false)
}