android - Android Jetpack Navigation 组件问题,将启动片段作为根目的地
问题描述
假设我们有 3 个带有向上按钮功能的工具栏片段
SplashFragment -> FragmentA -> FragmentB
这是应用程序的预期流程。当用户按下返回按钮时到达 FragmentB,他应该转到 FragmentA,然后再次按下返回按钮,应用程序应该退出。我们如何使用导航组件来实现这种行为?我尝试使用标签app:popUpTo
内部来做到这一点action
,不知何故我设法使它适用于硬件后退按钮,但向上按钮的行为没有改变。
在这方面需要帮助。
解决方案
警告:这在 Navigation alpha08 上已弃用,并且链接是当前的解决方案。
这可能是你想要的答案。利用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"/>
推荐阅读
- c# - 使用 Where 谓词过滤 detail.List 与另一个列表
- phonegap - PhoneGap:如何在 index.html 启动之前删除 Hello 字屏幕
- php - 如何循环通过 3 维数组将数据插入数据库?
- amazon-web-services - 我的 AWS Elastic Beanstalk 应用程序消失了
- javascript - RequireJS 的配置以咨询 node_modules?
- ios - 难以处理集合视图单元的可重用性。
- kubernetes - Pod 中的 2 个容器是否可以共享相同的环境变量?
- python - 比较 Pandas Dataframe 的列名
- swift - 将字符串从自定义分段控件设置为 UITextField 导致崩溃
- mysql - MySQL多次选择条件列