TabHost的使用
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的使用的更多相关文章
- 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 错误. 总结一下发生错误的原因,一般的 ...
- Android 轮换页面+TabHost 实例
最终效果展示: 首先我们需要一个ViewPager控件,不过可以发现在左侧的控件列表中并没有这个控件 这时我们要去升级包中查看 然后在厘米找到 ViewPager.class 这时我们双击这个发现不能 ...
- tabhost 下 setOnItemClickListener失效的问题
分析了一下代码,应该是tabhost 的ontabchangedListener接管了下面应该由setOnItemClickListener接管的部分,导致不能相应setOnItemClickList ...
- 安卓初級教程(5):TabHost的思考
package com.myhost; import android.os.Bundle; import android.view.LayoutInflater; import android.wid ...
- Android 实现分页(使用TabWidget/TabHost)
注:本文为转载,但该内容本人已亲身尝试,确认该方法可行,代码有点小的改动,转载用作保存与分享. 原作者地址:http://gundumw100.iteye.com/blog/853967 个人吐嘈:据 ...
- 安卓TabHost页面
<?xml version="1.0" encoding="UTF-8"?> <!-- TabHost组件id值不可变--> <T ...
- Android TabHost使用
TabHost是Android中自带的选项卡控件,效果图如下: 主布局文件 <RelativeLayout xmlns:android="http://schemas.android. ...
- tabhost使用
Tabhost用法 使用方法一:使用同一个布局文件 在xml中如此定义tabhost: <RelativeLayout xmlns:android="http://schemas.an ...
- tab使用 TabActivity TabHost Tabspec常用方法
本文是参考Android官方提供的sample里面的ApiDemos的学习总结. TabActivity 首先Android里面有个名为TabActivity来给我们方便使用.其中有以下可以关 ...
- Android工作学习第5天之TabHost实现菜单栏底部显示
TabHost是一个装载选项卡窗口的容器,实现分模块显示的效果.像新浪微博客户端.微信客户端都是使用tabehost组件来开发的. TabHost的组成: |---TabWidget:实现标签栏,可供 ...
随机推荐
- flex swf和movieclip之前的微妙关系
开始不清楚, 一直尝试想load图片一样加载一个swftools转换的swf,然后在尝试转换成movieclip的时候,总是报错, avmiMovieClip 不能转换成movieclip之类的. 但 ...
- Java用来进行批量文件重命名,批量提取特定类型文件
原因: 因为在网上下载视频教程,有的名字特别长,一般都是机构或者网站的宣传,不方便直接看到视频的简介,所以做了下面的第一个功能. 因为老师发的课件中,文件夹太多,想把docx都放在同一个文件夹下面,一 ...
- Mongodb安装与配置详解
简介: mongodb作为一款通用型数据库,除了能够创建,读取,更新和删除数据外,还提供一系列不断扩展的独特功能. a.索引: mongodb支持二级索引,允许多种快速查询,且提供和唯一索引,复合索引 ...
- Python中的字符串与字符编码
本节内容: 前言 相关概念 Python中的默认编码 Python2与Python3中对字符串的支持 字符编码转换 一.前言 Python中的字符编码是个老生常谈的话题,同行们都写过很多这方面的文章. ...
- Sql Server 的本地时间和UTC时间
一,本地时间和UTC时间 本地时间 世界的每个地区都有自己的本地时间,整个地球分为二十四时区,每个时区都有自己的本地时间. UTC时间 在国际无线电通信中,为统一而普遍使用一个标准时间,称为通用协调时 ...
- 反质数问题,求不大于n的最大反质数
反质数:设f(n)表示n个约数的个数,如果对于任意x有0<x<n, f(x) < f(n),那么n就是一个反质数 我们都知道对于任意一个数n,都可以用质数乘积的形式表示出来:x = ...
- 使用Expression Tree构建动态LINQ查询
这篇文章介绍一个有意思的话题,也是经常被人问到的:如何构建动态LINQ查询?所谓动态,主要的意思在于查询的条件可以随机组合,动态添加,而不是固定的写法.这个在很多系统开发过程中是非常有用的. 我这里给 ...
- Java面试题技术类一
1.面向对象编程的三大特性是什么? (1).继承: 继承是一种联结类的层次模型,并且允许和鼓励类的重用,它提供了一种明确表述共性的方法.对象的一个新类可以从现有的类中派生,这个过程称为类继承.新类继 ...
- Spring MVC 学习总结(三)——请求处理方法Action详解
Spring MVC中每个控制器中可以定义多个请求处理方法,我们把这种请求处理方法简称为Action,每个请求处理方法可以有多个不同的参数,以及一个多种类型的返回结果. 一.Action参数类型 如果 ...
- Sybase 数据库新增用户,赋权
Sybase数据库, 需求:新增用户user1,赋予对原数据库中表t_jingyu的查询权限 数据库原用户登陆 isql -U用户 -P密码 -S服务名 sp_addlogin 'user1','us ...