gpt4 book ai didi

android - Android Jetpack Navigation组件问题,飞溅 fragment 为根目标

转载 作者:行者123 更新时间:2023-12-02 13:22:29 25 4
gpt4 key购买 nike

假设我们有3个片段,其中包含带有向上按钮功能的工具栏

SplashFragment -> FragmentA -> FragmentB 

这是应用程序的预期流程。当用户按下后退按钮到达FragmentB时,他应转到FragmentA,然后再次按下后退应用程序应退出。
我们如何使用导航组件实现此行为?
我尝试使用 app:popUpTo标记内的 action进行此操作,以某种方式设法使它适用于硬件后退按钮,但向上按钮的行为没有改变。

需要帮助。

最佳答案

警告:导航alpha08上已弃用此方法,并且link是当前解决方案。

这可能是您想要的答案。
使用app:clearTask="true"

<fragment
android:id="@+id/splashFragment"
android:name="xxx.SplashFragment"
android:label="fragment_splash"
tools:layout="@layout/fragment_splash">
<action
android:id="@+id/action_splashFragment_to_mainFragment"
app:destination="@id/mainFragment"
app:enterAnim="@anim/anim_right_in"
app:exitAnim="@anim/anim_left_out"
app:popEnterAnim="@anim/anim_left_in"
app:popExitAnim="@anim/anim_right_out"
app:clearTask="true"/>

Navigation Architecture Component - Splash screen

关于android - Android Jetpack Navigation组件问题,飞溅 fragment 为根目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52537502/

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