Android:更改选项卡视图
我有一个带有三个选项卡的 TabHost;每人举办一项活动。
我想将一个选项卡的视图更改为另一个视图 - 如何以编程方式执行此操作?我不喜欢使用 ActivityGroups,因为我在使用 ActivityGroups 时遇到了一些问题。
如果我可以在当前视图之上添加一个视图,那么后退按钮也可以工作(或者至少我可以获取后退按钮并删除最上面的视图),那就完美了。
I've got a TabHost with three tabs; each holding one activity.
I'd like to change the view of one tab to another view - how can I do that programatically? I don't like to use ActivityGroups, as I've experienced several problems with ActivityGroups.
It would be perfect if I could add a View on top of the current one, so the back button is working, too (or at least I could fetch the back button and remove the topmost view).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当前选项卡的内容视图是您指定@android:id/content id 的布局的子级。您应该能够使用 http://developer.android.com 访问它/reference/android/widget/TabHost.html#getTabContentView()。
在那里您基本上可以根据需要添加或删除视图。
非活动选项卡的内容视图不可公开访问,并且如果之前未选择该选项卡,则可能尚未创建。
请记住,TabHost 实际上并不使用 Activity,它只是将它们转换为视图。
不过,您必须自己实现后退按钮。
The content view of the current tab is a child of the layout which you gave the @android:id/content id. You should be able to access it using http://developer.android.com/reference/android/widget/TabHost.html#getTabContentView().
There you can basically add or remove views as you wish.
The content views of inactive tabs are not publicly accessible, and might not be created yet if the tab wasn't selected previously.
Keep in mind that TabHost doesn't actually use Activities, it just turns them into views.
You'd have to implement the back button yourself, though.