一,创建三个Activity类

MainActiviey.java

package tianshuai.home_page; import android.app.Activity; import android.app.ActivityGroup; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.TabHost; import android.widget.TabHost.TabSpec; public class MainActivity extends ActivityGroup implements View.OnClickListener { public static TabHost tab_host; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); createTab(); } public void createTab() { tab_host = (TabHost) findViewById(R.id.tab_host); tab_host.setup(this.getLocalActivityManager()); tab_host.setOnClickListener(this); TabSpec ts1 = tab_host.newTabSpec("手机酷站"); ts1.setIndicator("正在播放", getResources().getDrawable(R.drawable.find)); ts1.setContent(new Intent(this, cellphone_web.class)); tab_host.addTab(ts1); TabSpec ts2 = tab_host.newTabSpec("软件游戏"); ts2.setIndicator("本地曲库", getResources().getDrawable(R.drawable.history)); ts2.setContent(new Intent(this, software.class)); tab_host.addTab(ts2); tab_host.setCurrentTab(1); } public void onClick(View arg0) { throw new UnsupportedOperationException("Not supported yet."); } }
二,cellphone_web.java 跟 software.java均为继承 Activity 的空类就可以

三,main.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TabHost android:id="@+id/tab_host" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dp" android:layout_weight="1" /> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0" /> </LinearLayout> </TabHost> </LinearLayout>
注意:TabWidget和FrameLayout 有不同的ID命名空间android:id="@android:id/idnames",这个是必须的因此TabHost才能自动找到它,Activity需要继承TabActivity。

如果想让选项卡在上方的话:

<FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dp" android:layout_weight="0" /> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />内容想在上边,TabWidget 必须与 FrameLayout 换换位置

转载于:https://www.cnblogs.com/JPAORM/archive/2012/03/29/2510016.html

【Android】选项卡使用相关推荐

  1. android 选项卡的实现

    转载:https://blog.csdn.net/itachi85/article/details/50412332 前言 此前我们用HorizontalScrollView也实现了类似网易选项卡动态 ...

  2. Android选项卡置底的方法

    发现很多Android应用的选项卡 都是显示在页面底部的,网上有资料:通过反射获取TabWidget中的私有变量,改变其值.今天反编译了腾讯微薄,发现实现这个很简单, 只需将布局文件中<TabW ...

  3. android 选项卡TabHost

    选项卡主要有TabHost.TabWiget和 FramentLayout3个组件组成,用于实现一个多标签的用户界面,通过他可以将一个复杂的对话分隔成若干个标签页,实现对信息的分类显示和管理.使用给组 ...

  4. 【笔记】与Android选项卡一周

    果然,还是项目驱动的学习方式比较有趣呢. 这周的学习全部围绕着选项卡,也就是tab. 用到了好多知识点,都不知道从哪里开始啦(≧o≦*). 选项卡的制作有很多方法.选项菜单可以用普通的TextView ...

  5. android动态添加顶部tab,android选项卡(Tab)实现顶部和底部

    1.自己创建一XML文件放于layout文件夹tab.xml(选项卡在顶部) encoding="utf-8"?> android:layout_width="fi ...

  6. Android --- 选项卡背景样式,左侧边有颜色

    效果图: 代码如下: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:and ...

  7. Android选项卡

    一:布局文件activity.xml <?xml version="1.0" encoding="utf-8"?> <TabHost xmln ...

  8. Android之选项卡

    1.Android选项卡主要由TabHost,TabWidget,FrameLayout三个组件组成,用于实现一个多标签页的用户界面,通过它可以将一个复杂的对话框分割成若干个标签页,实现对信息的分类显 ...

  9. Android快速开发-选项卡

    介绍 几行代码实现Android选项卡界面,支持标准底部Tab自定义视图选项卡,头部文字选项卡. 底部自定义视图选项卡 先来看看实现下图中的效果我们代码应该怎么写? 实现上图效果只需以下代码: pub ...

  10. Windows Azure Mobile Services增加了对 Android的支持并扩展其适用范围至东亚地区

    我们的Mobile Services使开发人员很容易地开发丰富多彩的移动应用程序.使用Mobile Services ,开发人员不仅能够连接其应用程序到 Windows Azure 上易扩展又安全的后 ...

最新文章

  1. Kafka史上最详细原理总结 ----看完绝对不后悔
  2. 关于org.apache.lucene.queryParser.ParseException: Encountered 解决方法
  3. Spring boot优点
  4. 百度模糊搜索怎么实现_百度搜索广告是什么?百度搜索竞价广告投放推广效果怎么样?...
  5. JQuery-让Ajax变的更简单
  6. 【springboot】之自动配置原理
  7. java集合——映射表+专用集合映射表类
  8. Golang——单元测试testing
  9. React-Native测试报告
  10. 数据库技大会五周年 技术领袖共聚DTCC
  11. 开源,免费,跨平台——白鹭引擎(Egret Engine)
  12. 平民级NER︱pycrfsuite的介绍与应用
  13. mysql 数据备份 crontab
  14. 【记录】非常实用,Python编码规范的一些建议(1)
  15. 162-SOP8液晶手写板专用IC
  16. 【网络编程】TCP 网络应用程序开发
  17. 【已解决】docker overlay2占用大量磁盘空间处理方法
  18. iOS 给NSString文字中间或底部添加横线
  19. python计算化学浓度_计算化学操作流程-孙磊.pdf
  20. 案例精选 | 志翔科技:安全与高效并重 构筑芯片行业数据安全堡垒

热门文章

  1. 数据库 一致性读当前读
  2. 很囧的实验:一辆奥迪究竟值多少女大学生? 阅读 3056 回复 12 [回复] [编辑] [修改]...
  3. 城市管网 GIS 数据表的存储
  4. 双指针:JZ21调整数组顺序使奇数位于偶数前面 Offer 57. 和为s的两个数字
  5. uml学习之图书借阅简化用例图创建
  6. 同样是做大数据分析,你月薪8k他30k,到底差在了哪?
  7. python3 源码_7. Python3源码—Dict对象-阿里云开发者社区
  8. python爬取bilibili弹幕_GitHub - yxwangnju/Bilibili-Bullet-Screen-Crawler: 一个爬取bilibili上弹幕的简单python程序...
  9. zabbix监控mysql 图_zabbix监控mysql
  10. 余弦函数导数推导过程_反三角函数的导数的推导过程