是否可以在 Android 的同一选项卡中打开新意图?
我有一个选项卡视图,它工作正常,但我想在选项卡中打开新意图。当我打开一个新意图时,它会替换整个屏幕,包括选项卡。需要进行哪些修改才能使其在同一选项卡中打开?
这是打开新意图的代码:
Intent i = new Intent();
i = new Intent();
i.setClassName("my.massive.package",
"my.massive.package.SecondIntent");
startActivity(i);
这是新选项卡的代码:
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("first").setIndicator("First")
.setContent(new Intent().setClass(this, FirstIntent.class)));
I have a tab view and it works fine, but I would like to open new intents in a tab. At the moment when I open a new intent, it replaces the entire screen, tab included. What modifications are needed to make this open in the same tab?
Here's the code for opening a new intent:
Intent i = new Intent();
i = new Intent();
i.setClassName("my.massive.package",
"my.massive.package.SecondIntent");
startActivity(i);
And here's the code for a new tab:
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("first").setIndicator("First")
.setContent(new Intent().setClass(this, FirstIntent.class)));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我解决了这个:体验 - TabActivity 中的多个 Android 活动
I solved with this: Experience - Multiple Android Activities in a TabActivity
它一定对你有帮助。您可以使用按钮作为选项卡,使用活动作为内容:
是可以在activityA内启动activityB吗?又如何?
It must help you. You can use buttons as Tabs and Activities as contents:
Is it possible to start activityB inside activityA? And how?
您可以删除所有选项卡并重新插入它们,其中相关选项卡具有不同的用途。
请参阅http://www.coderanch.com/t/460859/ Android/Mobile/TabHost-Remove-Tab
You can remove all tabs and re insert them with the tab in question having different intent.
see http://www.coderanch.com/t/460859/Android/Mobile/TabHost-Remove-Tab
Android系统不支持此功能。您无法在 TabHost 中交换活动,因为选项卡的内容是不可更改的。
一种解决方法是交换选项卡中显示的活动的根布局的内容。我做过一次,但我不能推荐它,因为你会得到一个非常复杂的活动。
最佳解决方案:重新设计您的应用程序,以便您不需要此功能及更多功能。
This is not supported by the Android system. You can not exchange activities in a TabHost because the content of a Tab is not changeable.
One workaround would be that you exchange the content of your root layout of your activity shown in a Tab. I did this once and I can not recommend it because you will get a really complex activity.
Best solution: Redesign your app so that you do not need this functionality and more.