如何从对话框导航到导航组件中的片段? [英] How to navigate from Dialog to Fragment in Navigation Component?

本文介绍了如何从对话框导航到导航组件中的片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在导航组件中从 DialogFragment 导航到 Fragment ,但是结果很奇怪.

当我从 DialogFragment 导航到 Fragment 时,背景片段正在更改为目标片段,并带有当前对话框,而不仅仅是移动到目标片段.

这是导航图.

 <导航xmlns:android ="http://schemas.android.com/apk/res/android"xmlns:app =" http://schemas.android.com/apk/res-autoxmlns:tools ="http://schemas.android.com/tools"android:id ="@@ id/home";app:startDestination =" @ + id/titleScreen"><片段android:id ="@@ id/titleScreen"android:name ="com.example.android.navigationadvancedsample.homescreen.Title"android:label =&"; @ string/title_home"工具:layout ="@ layout/fragment_title"<动作android:id =" @ + id/action_title_to_about"app:destination ="@ id/aboutScreen"/></fragment><对话android:id ="@@ id/aboutScreen"android:name =" com.example.android.navigationadvancedsample.homescreen.About"android:label =&"; @ string/title_about"工具:layout ="@ layout/fragment_about"<动作android:id =" @ + id/action_aboutScreen_to_register"app:destination =" @ id/register"/></dialog><片段android:id =" @ + id/register"android:name ="com.example.android.navigationadvancedsample.formscreen.Register"android:label ="fragment_leaderboard"工具:layout ="@ layout/fragment_leaderboard";/></导航> 

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

通过修复,我的意思是正常的对话框行为.假设我在片段 A 上方有一个对话框 D ,然后从 D 上的按钮移至片段 B strong>,屏幕上应显示 B .当我从 B 弹出时,它应该转到 A 上的 D 的上一阶段.

解决方案

感谢@musooff提交此错误

此问题已在导航2.1.0-alpha06和其他对话框不一致问题中得到解决,例如返回按钮,当对话框弹出.

但是,如果可以,请更新到2.1.0-beta02或更高版本.

I am trying to navigation from DialogFragment to Fragment in Navigation Component, but getting weird result.

When I navigate from DialogFragment to Fragment, background fragment is changing to target fragment with current dialog on top of it, instead of just moving to target fragment.

Here is the navigation graph.

<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>

Why I am getting this behavior or how to fix it?

By fixing I mean normal dialog behavior. Say, I have a dialog D on top of a fragment A and move to a fragment B from a button on D, the screen should show B. And when I pop back from B, it should go to previous stage of D on top of A.

解决方案

Thanks @musooff for filing this bug

This problem was fixed on Navigation 2.1.0-alpha06, along with others dialog inconsistencies like back button when Dialog is popped.

However, update to 2.1.0-beta02 or higher if you can.

这篇关于如何从对话框导航到导航组件中的片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆