【发布时间】:2019-05-31 02:35:13
【问题描述】:
我正在尝试在导航组件中从 DialogFragment 导航到 Fragment,但结果很奇怪。
当我从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>
为什么会出现这种行为或如何解决?
通过修复我的意思是正常的对话行为。比如说,我在片段 A 顶部有一个对话框 D,然后从 D 上的按钮移动到片段 B strong>,屏幕应显示 B。而当我从B弹回时,它应该会在A之上进入D的前一阶段。
【问题讨论】:
-
@ianhanniballake 真的是一个错误吗?如果有时我做错了,我只是不想提交错误
-
您所描述的不是正常的对话框行为-通常,从对话框中选择某些内容会永久关闭对话框(用户进行了选择,他们在该对话框中没有其他事情可做)-为此,您将添加一个
app:popUpTo="@+id/aboutScreen" app:popUpToInclusive="true"。但是您并没有要求这种行为,您要求对话框在您点击后退按钮后返回,这不是受支持的,应该作为功能请求/错误提交。 -
@ianhanniballake 我相信你知道得更清楚,但你所描述的行为适用于 AlertDialog,在其中我有简单的基本操作,比如是或否,用户会选择,而你不需要对话。但在 DialogFragment 的情况下,我们通常会有一些复杂的对话框。假设有一个注册页面,当用户单击注册按钮时,我会在其中显示 UserAgreement PopUp。在我的 UserAgreement PopUp 上,我会有 PrivacyPolicy Page 的链接,用户可以去那里并且应该能够回到 UserAgreement PopUp
-
每个对话框都应该由 DialogFragment 管理(对话框本身不会在配置更改等情况下保留下来),无论它多么“复杂”。您的用例似乎是合理的,这就是为什么您应该提交一个错误以使其成为可能。
标签: android android-fragments android-dialogfragment android-navigation android-architecture-navigation