简体   繁体   English

在导航抽屉中使用片段进行导航

[英]Navigation with fragments in navigation drawer

Let me describe situtation : I have activity that has navigation drawer that has items A, B, C, D, S(PreferencesFragment). 让我描述情景:我有一个活动,该活动的导航抽屉中包含项A,B,C,D,S(PreferencesFragment)。 Now as user goes into app he can choose whatever he wants. 现在,随着用户进入应用,他可以选择自己想要的任何东西。 Lets say he click on B this opens new fragmentB that has list of some items. 假设他单击B,这将打开具有某些项目列表的新fragmentB。 Clicking on item opens new fragmentDetails and puts transaction of fragments to back stack to enable user to go back to fragmentB with list. 单击项目将打开新的fragmentDetails,并将事务片段放回堆栈,以使用户可以使用列表返回fragmentB。
Let user still be on fragmentDetails, if he now chooses to go to fragmentS from nav. 如果用户现在选择从导航转到fragmentS,则让用户仍然在fragmentDetails上。 drawer I would like the back stack to be empty. 抽屉我想把后排的箱子弄空。 Is there any way how to let back stack to forget about remaining transactions ? 有什么办法让后退堆栈忘记剩余的交易吗? I dont mean like popBackStack, becouse this would result into for a some small amont of time showing fragmentB. 我的意思不是像popBackStack一样,因为这会导致显示片段B的时间缩短。

How to achive this kind of navigation ? 如何实现这种导航?

lupajz, please take some time to consider on which fragments the user will have access to the navigation drawer. lupajz,请花点时间考虑用户可以使用哪些片段访问导航抽屉。 Most of the time when you reach a "item details" fragment you may wan't to offer a different kind of navigation. 大多数时候,当您到达“项目详细信息”片段时,您可能会不想提供其他类型的导航。

What you want to achieve can be done using this line: 您可以使用以下代码来实现:

getSupportFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);

Nevertheless please take a look at the following blog posts I've written covering this issues: 不过,请看一下我写的有关此问题的以下博客文章:

https://aarcoraci.wordpress.com/2017/02/13/android-tutorial-drawer-and-fragment-navigation-made-easyier/ https://aarcoraci.wordpress.com/2017/02/13/android-tutorial-drawer-and-fragment-navigation-made-easyier/

https://aarcoraci.wordpress.com/2017/02/14/android-drawer-and-fragment-navigation-a-more-real-life-scenario/ https://aarcoraci.wordpress.com/2017/02/14/android-drawer-and-fragment-navigation-a-more-real-life-scenario/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM