独立的返回堆栈使用片段在Android中每个标签 [英] Separate Back Stack for each tab in Android using Fragments

查看:136
本文介绍了独立的返回堆栈使用片段在Android中每个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个Android应用程序的选项卡进行导航。由于TabActivity和的ActivityGroup是德precated我想用片段,而不是实现它。

I'm trying to implement tabs for navigation in an Android app. Since TabActivity and ActivityGroup are deprecated I would like to implement it using Fragments instead.

我知道如何设置一个片段为每个选项卡,然后切换片段一个选项卡时。但我怎么能有一个独立的回栈为每个标签?

I know how to set up one fragment for each tab and then switch fragments when a tab is clicked. But how can I have a separate back stack for each tab?

有关的例子片段A和B是标签1和片段C和D在标签下2.当应用程序被启动片段A显示和Tab 1时。然后片段A可能被替换为片段B.当标签2选择C片段应显示。如果标签1,然后选择片段B应当再次显示。在这一点上应该有可能使用后退按钮来显示片段A

For an example Fragment A and B would be under Tab 1 and Fragment C and D under Tab 2. When the app is started Fragment A is shown and Tab 1 is selected. Then Fragment A might be replaced with Fragment B. When Tab 2 is selected Fragment C should be displayed. If Tab 1 is then selected Fragment B should once again be displayed. At this point it should be possible to use the back button to show Fragment A.

此外,重要的是,该状态为每个标签时,该设备被旋转被维持。

Also, it is important that the state for each tab is maintained when the device is rotated.

BR 马丁

推荐答案

将当前没有为你做这个自动的框架。您将需要建立和管理自己的背部栈为每个标签。

The framework won't currently do this for you automatically. You will need to build and manage your own back stacks for each tab.

说实话,这似乎是一个非常值得怀疑的事情。我无法想象它导致一个体面的用户界面 - 如果返回键会做不同的事情取决于我的标签上,特别是如果返回键还具有关闭整个活动的正常行为时,在顶部堆栈......听起来很讨厌的。

To be honest, this seems like a really questionable thing to do. I can't imagine it resulting in a decent UI -- if the back key is going to do different things depending on the tab I am, especially if the back key also has its normal behavior of closing the entire activity when at the top of the stack... sounds nasty.

如果您正在试图建立类似网络浏览器的用户界面,以获得一个用户体验是很自然的用户会涉及很多行为的细微调整的取决于具体的环境,所以你肯定会需要做的自己回堆栈管理,而不是依赖于该框架的一些默认实现。举一个例子尽量注意如何使用标准浏览器的返回键相互作用的各种方式,你可以去,出来吧。 (在浏览器中的每个窗口本质上是一个标签。)

If you are trying to build something like a web browser UI, to get a UX that is natural to the user is going to involve a lot of subtle tweaks of behavior depending on context, so you'll definitely need to do your own back stack management rather than rely on some default implementation in the framework. For an example try paying attention to how the back key interacts with the standard browser in the various ways you can go in and out of it. (Each "window" in the browser is essentially a tab.)

这篇关于独立的返回堆栈使用片段在Android中每个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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