TabHost与ActivityGroup整理

android应用中顶部和底部导航条使用甚多。

个人经验:使用activitygroup比较灵活,特别是在同一个选项卡中切换不同activity的时候,tabhost使用比较方便,但是不怎么灵活,可定制性差。好了,不多说,帖子整理如下:

tabhost相关帖子:
1.农民伯伯整理:http://www.cnblogs.com/over140/archive/2011/03/02/1968042.html
2.eoe论坛牛帖:http://www.cnblogs.com/over140/archive/2010/09/07/1820876.html
2.hellogv整理:http://blog.csdn.net/hellogv/article/details/6057174
3.跳转分析:http://hi.baidu.com/qinxiaowei137/blog/item/32a3761703ba6febc3ce798b.html

tabhost和activitygroup综合帖
1.差异性比较:http://blog.sina.com.cn/s/blog_4ca9ceef0100zu6b.html
2.综合使用:http://blog.csdn.net/lfyx1357/article/details/7467194





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TabHost 是 Android 中的一个容器,用于实现多个标签页之间的切换。下面是 TabHost使用方法详解: 1. 在 XML 布局文件中添加 TabHost 控件: ```xml <TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> </LinearLayout> </TabHost> ``` 2. 在 Activity 中初始化 TabHost: ```java TabHost tabHost = findViewById(android.R.id.tabhost); tabHost.setup(); ``` 3. 添加标签页: ```java TabHost.TabSpec tabSpec1 = tabHost.newTabSpec("Tab1"); tabSpec1.setIndicator("Tab 1"); tabSpec1.setContent(R.id.tab1_content); TabHost.TabSpec tabSpec2 = tabHost.newTabSpec("Tab2"); tabSpec2.setIndicator("Tab 2"); tabSpec2.setContent(R.id.tab2_content); tabHost.addTab(tabSpec1); tabHost.addTab(tabSpec2); ``` 4. 创建标签页的布局: 在布局文件中创建用于显示每个标签页内容的 View,例如: ```xml <LinearLayout android:id="@+id/tab1_content" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- 在这里添加 Tab 1 的内容 --> </LinearLayout> <LinearLayout android:id="@+id/tab2_content" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- 在这里添加 Tab 2 的内容 --> </LinearLayout> ``` 以上就是 TabHost 的基本使用方法。通过添加不同的标签页和对应的布局,可以实现多个标签页之间的切换和显示不同的内容。你可以根据自己的需求来定制标签页的样式和内容。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值