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

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

问题描述

对于一个新的应用程序,我使用Jetpack导航库来实现适当的向后导航.导航的第一级是导航抽屉,它可以与文档中所述的jetpack导航配合使用.但是,ViewPager和TabLayout实现了另一级导航. TabLayout切换的片段包含其他线性导航层次结构.但是,Jetpack导航中似乎不支持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?

推荐答案

使用 Jetpack Navigation 处理不同方法来处理TabLayout的实验.但遇到一些麻烦的问题,例如具有在选项卡之间多次切换的完整历史记录等.

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管理选项卡-引用

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天全站免登陆