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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
What worked for me so far:
In navigation_graph.xml
- make your ViewPagerFragment the root of a nested graph
- connect your in and out navigation to the nested graph
in nested graph:
- add the ChildFragments of the ViewPager to the nested graph
I didnt need to change the ViewPager, and Directions were created for the Child Fragments so navigation is possible from there.