Android TabHost - 每个选项卡内的活动
我正在尝试创建多个选项卡,每个选项卡都有不同的活动。唯一的缺点是我使用自定义布局文件,因此我的类扩展了 Activity 而不是 TabActivity。在尝试运行时,它失败并建议调用 TabHost.Setup(ActivityGroupManager agm)
有人知道如何实现这一点的想法/实际示例吗?
提前致谢
I'm trying to create multiple Tabs, each with a different Activity. The only downside is i'm using a custom layout file thus my class extends an Activity rather than a TabActivity
. While trying to run, it fails and suggests calling TabHost.Setup(ActivityGroupManager agm)
Anyone have an idea/practical example of how this can be achieved?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我的活动示例,它也不是从 TabActivity 扩展的:
This is a sample of my activity that also doesn't extend from TabActivity:
首先,在主布局中定义一个frametab。
然后,创建一个从 TabActivity 扩展的活动。
如果您想滚动选项卡,请使用选择器布局:
以下是示例屏幕截图。
替代文本 http://rayyildiz.com/wp-content/ uploads/2010/06/android_sample_tab-201x300.png 替代文本http://rayyildiz.com/wp-content/uploads/2010/06/android_sample_tab2-201x300.png
Firstly, define a frametab in main layout.
Then, create a activity extends from TabActivity
If you want to rolover tab, use selector layout:
Here is sample screenshots.
alt text http://rayyildiz.com/wp-content/uploads/2010/06/android_sample_tab-201x300.png alt text http://rayyildiz.com/wp-content/uploads/2010/06/android_sample_tab2-201x300.png
创建一个扩展
TabActivity
的附加类,并使该类成为主活动。要在 XML 清单中执行此操作,您将包括:
在此类中,您将编写如下内容:
这个 TabActivty 类可以根据您的需要大小,但通常它会是全屏,每个选项卡的 Activity 都会加载到屏幕的主要部分,如下所示:
(来源:android.com)
PS 另请注意,Eclipse 布局编辑器不支持选项卡。这是已记录的错误。
Make an additional Class which extends
TabActivity
and make that class the main activity.To do that in your XML manifest you would include:
In this class you would write something like:
This TabActivty class can be as big or small as you would like, but typically it would be the full screen, with each tab's Activity being loaded into the main part of the screen, like so:
(source: android.com)
P.S. Also be aware that the Eclipse Layout Editor doesn't work with Tabs. It is a bug which has already been logged.