带有 ViewPager 和 TabLayout 的 Android Jetpack 导航 [英] Android Jetpack Navigation with ViewPager and TabLayout

本文介绍了带有 ViewPager 和 TabLayout 的 Android Jetpack 导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个新的应用程序,我使用 Jetpack 导航库来实现正确的返回导航.第一级导航是导航抽屉,如文档中所述,它可以与喷气背包导航配合使用.但是还有另一个层次的导航是用 ViewPager 和 TabLayout 实现的.TabLayout 切换的片段包含额外的线性导航层次结构.但是,Jetpack Navigation 似乎不支持 ViewPager/TabLayout.必须实现 FragmentPagerAdapter 并且在切换选项卡时管理后台堆栈结束.顶级导航与每个选项卡内的导航之间存在脱节.有什么办法可以让 Jetpack Navigation 做到这一点?

For a new app i use Jetpack Navigation Library to implement proper back navigation. The first level of navigation is a navigation drawer which works fine with jetpack navigation as described in the documentation. But there is another level of navigation implemented with ViewPager and TabLayout. The fragments switched by the TabLayout contain additional linear navigation hierarchy. However, there seems to be no support for ViewPager/TabLayout in Jetpack Navigation. A FragmentPagerAdapter has to be implemented and the managed back stack ends when switching tabs. There is a disconnect between the top level navigation and the navigation inside each tab. Is there any way to make this work with Jetpack Navigation?

推荐答案

试验了不同的方法来处理 TabLayoutJetpack Navigation.但是遇到了诸如在标签之间多次切换的完整历史记录等问题.

Experimented with different approaches to handle TabLayout with Jetpack Navigation. But hit issues like having a full history of switching between tabs multiple times etc.

在提出演示请求之前浏览已知的 Google Android 问题,我发现了这个现有问题.

Browsing known Google Android Issues before raising a request for a demo, I found this existing issue.

其状态为关闭,标记为预期行为,并附有以下说明:

Its status is Closed marked as Intended Behavior with the following explanation:

导航侧重于影响后退堆栈的元素,而选项卡不影响后退堆栈-您应该继续使用 ViewPagerTabLayout 管理选项卡-参考 Youtube 培训.

Navigation focuses on elements that affect the back stack and tabs do not affect the back stack - you should continue to manage tabs with a ViewPager and TabLayout - Referring to Youtube training.

这篇关于带有 ViewPager 和 TabLayout 的 Android Jetpack 导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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