gpt4 book ai didi

android - 使用 DialogFragment 作为 Android NavController 中的 fragment 之一

转载 作者:行者123 更新时间:2023-12-05 00:00:07 26 4
gpt4 key购买 nike

我有一个使用 XML 定义的图表,我在 NavGraph 中添加了一个 DialogFragment 作为 fragment 之一。当我在该导航 Controller 上使用 resId 和 bundle 调用 NavController.navigate 时,我没有看到显示任何对话框。有什么方法可以使用 DialogFragment 而不是标准 Fragment?

<fragment
android:id="@+id/noLoginDialog"
android:name="com.ram.view.NoLoginDialog"
android:label="NoLoginDialog">
<argument
android:name="argTitle"
android:defaultValue="null"
app:type="string"/>
<argument
android:name="argBody"
android:defaultValue="null"
app:type="string"/>
<argument
android:name="argButton"
android:defaultValue="null"
app:type="string"/>
</fragment>

我的 Action 定义如下

 <container_fragment
android:id="@+id/homeFragment"
android:name="com.ram.home.HomeFragment"
android:label="HomeFragment">

<action
android:id="@+id/action_homeFragment_to_noAuthAlertDialog"
app:destination="@id/noLoginDialog"/>
</container_fragment>

我对 Activity 和 fragment 的其他操作工作得很好。

最佳答案

嗯,导航库永远不会将 fragment 作为对话框打开,它只是将第一个(主页目的地)替换为 NavHostFragment 中的其他目的地。

谷歌说:

A destination is any place you can navigate to in your app. While destinations are usually Fragments representing specific screens..

请提供更多信息,例如您的导航代码 (java/kotlin)。

阅读这篇 Google 官方帖子,了解有关导航的更多信息: https://developer.android.com/topic/libraries/architecture/navigation/navigation-implementing

关于android - 使用 DialogFragment 作为 Android NavController 中的 fragment 之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51756325/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com