有没有办法在TabHost中显示片段?
我想在 TabHost 中为每个选项卡显示不同的片段。但 似乎没有简单的方法可以做到这一点。 TabHost只能接受 A. 视图或 B. 当用户选择某个活动时启动活动的意图 选项卡。
使用 A 意味着我必须初始化每个片段并加载 将它们放入提供给 TabHost 的容器视图中。但我想要 这些片段仅在需要时加载 - 当用户选择他们的 选项卡就是。
使用 B 意味着我将片段加载到单独的 Activity 中 对于每个选项卡。但我希望片段能够到达 “原始”父 Activity,而不仅仅是托管的一些 shell Activity 它们在选项卡内容中。
我错过了什么吗?有没有办法管理片段 TabHost 正确吗?
I'd like to show a different fragment in a TabHost, for every tab. But
it seems that there's no easy way to do this. TabHost can only accept
A. Views or B. Intents that launch Activities when the user selects a
tab.
Going with A means that I have to initialize every fragment and load
them into container Views that are given to the TabHost. But I want
these fragments to load only when needed - when the user selects their
tab that is.
Going with B means that I load the fragments into separate Activities
for each tab. But I'd like the fragment to be able to reach the
"original" parent Activity, not just some shell Activity that hosts
them in a tab content.
Am I missing something? Is there a way to manage fragments with
TabHost properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有一些点击:
据我了解,不允许在 TabHost 内“链接”片段,您需要创建包含片段的活动,然后从 TabHost 调用这些活动。
编辑
“官方解决方案”来自Google,并使用 漂亮的动画。
Some hits here:
For what I understood, "link" a fragment inside a TabHost isn't allowed, you need to create activities that include your fragments and then call these activities from TabHost.
EDIT
the "official solution" from Google, and with nice animations.