Android中的选项卡是用TabHost实现的。

首先,定义TabHost的布局文件:

<?xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"> <TabWidget android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/> <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" /> </LinearLayout> </TabHost>

其中,TabWidget即是选项卡上面的标签,FrameLayout是选项卡的内容。

在Java类文件中定义如下:

public class MainActivity extends TabActivity {

	private TabHost my_tabhost;
private TabWidget my_tabwidget;
private int i,k;
private TextView tv; private String[] tabMenu = { "系统", "硬件", "操作"};
private Intent intent0, intent1, intent2;
private Intent[] intents = { intent0, intent1, intent2};
private TabHost.TabSpec tabSpec0, tabSpec1, tabSpec2, tabSpec3;
private TabHost.TabSpec[] tabSpecs = { tabSpec0, tabSpec1, tabSpec2, tabSpec3}; public static Context mContext; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
         // 不要窗体标题
       requestWindowFeature(Window.FEATURE_NO_TITLE);
       setContentView(R.layout.activity_main);
setContentView(R.layout.activity_main); my_tabhost = getTabHost(); intent0 = new Intent(this, system.class);
intent1 = new Intent(this, hardware.class);
intent2 = new Intent(this, operation.class); tabSpec0 = my_tabhost.newTabSpec("system").setIndicator(tabMenu[0],null).
setContent(intent0);
tabSpec1 = my_tabhost.newTabSpec("hardware").setIndicator(tabMenu[1],null).
setContent(intent1);
tabSpec2 = my_tabhost.newTabSpec("operation").setIndicator(tabMenu[2],null).
setContent(intent2); my_tabhost.addTab(tabSpec1);
my_tabhost.addTab(tabSpec0);
my_tabhost.addTab(tabSpec2);

     // 设置默认选中的选项卡为第2个
my_tabhost.setCurrentTab(1); } }

每一个选项卡对应一个Intent,每一个Intent又对应一个类,选中这个选项卡时,就显示对应的类。

运行结果如下:

TabHost的使用的更多相关文章

  1. android 使用Tabhost 发生could not create tab content because could not find view with id 错误

    使用Tabhost的时候经常报:could not create tab content because could not find view with id 错误. 总结一下发生错误的原因,一般的 ...

  2. Android 轮换页面+TabHost 实例

    最终效果展示: 首先我们需要一个ViewPager控件,不过可以发现在左侧的控件列表中并没有这个控件 这时我们要去升级包中查看 然后在厘米找到 ViewPager.class 这时我们双击这个发现不能 ...

  3. tabhost 下 setOnItemClickListener失效的问题

    分析了一下代码,应该是tabhost 的ontabchangedListener接管了下面应该由setOnItemClickListener接管的部分,导致不能相应setOnItemClickList ...

  4. 安卓初級教程(5):TabHost的思考

    package com.myhost; import android.os.Bundle; import android.view.LayoutInflater; import android.wid ...

  5. Android 实现分页(使用TabWidget/TabHost)

    注:本文为转载,但该内容本人已亲身尝试,确认该方法可行,代码有点小的改动,转载用作保存与分享. 原作者地址:http://gundumw100.iteye.com/blog/853967 个人吐嘈:据 ...

  6. 安卓TabHost页面

    <?xml version="1.0" encoding="UTF-8"?> <!-- TabHost组件id值不可变--> <T ...

  7. Android TabHost使用

    TabHost是Android中自带的选项卡控件,效果图如下: 主布局文件 <RelativeLayout xmlns:android="http://schemas.android. ...

  8. tabhost使用

    Tabhost用法 使用方法一:使用同一个布局文件 在xml中如此定义tabhost: <RelativeLayout xmlns:android="http://schemas.an ...

  9. tab使用 TabActivity TabHost Tabspec常用方法

    本文是参考Android官方提供的sample里面的ApiDemos的学习总结.   TabActivity   首先Android里面有个名为TabActivity来给我们方便使用.其中有以下可以关 ...

  10. Android工作学习第5天之TabHost实现菜单栏底部显示

    TabHost是一个装载选项卡窗口的容器,实现分模块显示的效果.像新浪微博客户端.微信客户端都是使用tabehost组件来开发的. TabHost的组成: |---TabWidget:实现标签栏,可供 ...

随机推荐

  1. CGFloat Float 互转

    直接上代码吧 var positionX:CGFloat = 10 var positionY:CGFloat = 20 var tmpX:Float = 30 var tmpY:Float = 40 ...

  2. 10 个 Redis 建议/技巧

    转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/145.html?1455790611 Redis 在当前的技术社区里是非常 ...

  3. Node.js与Sails~中间查询语言Waterline

    回到目录 上讲主要说了如何配置sails的持久化机制,这讲主要说一下实现持久化时的增删改查的语法,在sails里使用了和mongodb风格类似的waterline查询语言,使用简单,语法生动,下面我们 ...

  4. 基础才是重中之重~C#中标准的IDispose模式

    回到目录 IDispose模式在C++中用的很多,用来清理资源,而在C#里,资源分为托管和非托管两种,托管资源是由C#的CLR帮助我们清理的,它是通过调用对象的析构函数完成的对象释放工作,而对于非托管 ...

  5. 品味FastDFS~目录

    回到占占推荐博客索引 参考文献:http://baike.baidu.com/view/973383.htm#sub5143372 分布式文件系统(DFS,Distributed File Syste ...

  6. VM~Linux联不上网

    使用桥接的链接方式,centos6.4配置静态ip,能ping通网关,但ping 外网时出现 "network is unreachable" 如:ping www.baidu.c ...

  7. ci框架里rewrite示例

    ci里新建应用app,入口文件app.php. Nginx 这里附上vhost配置 app.52fhy.com.conf server { listen 80; server_name app.52f ...

  8. iOS开发——网络使用技术OC篇&网络爬虫-使用正则表达式抓取网络数据

    网络爬虫-使用正则表达式抓取网络数据 关于网络数据抓取不仅仅在iOS开发中有,其他开发中也有,也叫网络爬虫,大致分为两种方式实现 1:正则表达 2:利用其他语言的工具包:java/Python 先来看 ...

  9. PHP实现RESTful风格的API实例(一)

    最近看了一些关于RESTful的资料,自己动手也写了一个RESTful实例,以下是源码 目录详情: restful/ Request.php 数据操作类 Response.php 输出类 index. ...

  10. btn css

    .searchButtonBtn { border: 0; padding: 0 23px; height: 27px; line-height: 27px; cursor: pointer; bac ...