相关疑难解决方法(0)

DialogFragment 从它导航到另一个片段时关闭

目前在我的导航图中,我有对话片段目的地(片段(对话)类型)。当我导航到这个对话框,然后尝试从这个对话框目标导航到另一个片段时,对话框正在关闭,在我看来这是可预测的行为。

现在我只是像这样导航到下一个片段。

findNavController().popBackStack(R.id.testFragment, true)

我想不关闭对话框,只导航到另一个对话框,如默认片段。我怎样才能做到这一点?

android android-fragments kotlin

7
推荐指数
1
解决办法
868
查看次数

使用导航组件时关闭 DialogFragment 的正确方法?

我正在使用 Navigation 组件来显示DialogFragment(<dialog...>...</dialog>navigation.xml) 并想知道关闭对话框的推荐方法是什么。我自己试了一下,结果如下:

1)dismiss()DialogFragment:似乎工作正常

2)findNavController().navigateUp():似乎工作正常

3) findNavController().navigate(MyDialogFragmentDirections.actionMyDialogFragmentToMyNormalFragment()): 有效,但会加载目标目的地的新版本,因此根据用例,这可能不是人们想要的。

注:我使用的情况是,MyNormalFragment使用MyDialogFragment得到一些投入,所以以后MyDialogFragment所示,我需要找回的已经存在的实例MyNormalFragment

所以对我来说,只有 1) 或 2) 是正确的。现在我想知道,1) 和 2) 之间有什么区别吗?

navigation android android-architecture-components

6
推荐指数
1
解决办法
2279
查看次数

如何从对话框导航到导航组件中的片段?

我试图在导航组件中从导航DialogFragmentFragment,但是结果很奇怪。

在此处输入图片说明

当我从导航DialogFragment到时Fragment,背景片段会更改为目标片段,并在其顶部显示当前对话框,而不仅仅是移动到目标片段。

这是导航图。

<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/home"
    app:startDestination="@+id/titleScreen">

    <fragment
        android:id="@+id/titleScreen"
        android:name="com.example.android.navigationadvancedsample.homescreen.Title"
        android:label="@string/title_home"
        tools:layout="@layout/fragment_title">
        <action
            android:id="@+id/action_title_to_about"
            app:destination="@id/aboutScreen"/>
    </fragment>
    <dialog
        android:id="@+id/aboutScreen"
        android:name="com.example.android.navigationadvancedsample.homescreen.About"
        android:label="@string/title_about"
        tools:layout="@layout/fragment_about">
        <action
            android:id="@+id/action_aboutScreen_to_register"
            app:destination="@id/register" />
    </dialog>
    <fragment
        android:id="@+id/register"
        android:name="com.example.android.navigationadvancedsample.formscreen.Register"
        android:label="fragment_leaderboard"
        tools:layout="@layout/fragment_leaderboard" />
</navigation>
Run Code Online (Sandbox Code Playgroud)

为什么我会出现这种现象或如何解决?

修复是指正常的对话框行为。我说,我有一个对话框d上的一个分段的顶部一个,并移动到一个片段从一个按钮d,屏幕应该显示。当我从B弹出时,它应该转到A之上的D的前一阶段。

android android-fragments android-dialogfragment android-navigation android-architecture-navigation

5
推荐指数
1
解决办法
1262
查看次数