从零開始学android<TabHost标签组件.二十九.>
1
|
public TabHost(Context context)
|
构造
|
创建TabHost类对象
|
2
|
public void addTab(TabHost.TabSpec tabSpec)
|
普通
|
添加一个Tab
|
3
|
public TabHost.TabSpec newTabSpec(String tag)
|
普通
|
创建一个TabHost.TabSpec对象
|
4
|
public View getCurrentView()
|
普通
|
取得当前的View对象
|
5
|
public void setup()
|
普通
|
建立TabHost对象
|
6
|
public void setCurrentTab(int index)
|
普通
|
设置当前显示的Tab编号
|
7
|
public void setCurrentTabByTag(String tag)
|
普通
|
设置当前显示的Tab名称
|
8
|
public FrameLayout getTabContentView()
|
普通
|
返回标签容器
|
9
|
public void setOnTabChangedListener
(TabHost.OnTabChangeListener l)
|
普通
|
设置标签改变时触发
|
<? xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <LinearLayout
android:layout_marginTop="50dp"
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号" /> <EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="25sp" />
</TableRow> <TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" > <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="password" /> <EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="25sp" />
</TableRow> <TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content" > <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="取消" /> <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="登录" />
</TableRow>
</LinearLayout> <LinearLayout
android:layout_marginTop="50dp"
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/a2" />
</LinearLayout> <LinearLayout
android:layout_marginTop="50dp"
android:id="@+id/timer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TimePicker
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="50dp"
android:id="@+id/timer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TimePicker
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="50dp"
android:id="@+id/timer2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TimePicker
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
package com.example.tabhost; import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec; public class MainActivity extends TabActivity {
private TabHost tabHost;//初始化TabHost组件
private int reslayout[] = { R.id.login, R.id.image, R.id.timer , R.id.timer1,R.id.timer2};//设置相应的额xml文件
private int images[]={R.drawable.cart,R.drawable.cloud,R.drawable.comment,R.drawable.gear,R.drawable.joystick};//设置显示的标题文件 @SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.tabHost = super.getTabHost();//实例化TabHost组件
// 取得LayoutInflater对象
LayoutInflater.from(this).inflate(R.layout.linearlayout,//制定布局
this.tabHost.getTabContentView(),//制定标签添加的容器
true); for (int i = 0; i < reslayout.length; i++) {
TabSpec myTab = tabHost.newTabSpec("tab" + i);// 定义TabSpec
myTab.setIndicator(null,getResources().getDrawable(images[i])) ; // 设置标签 myTab.setContent(this.reslayout[i]) ; // 设置显示的组件
this.tabHost.addTab(myTab) ;
}
} }
效果图例如以下
使用配置文件设置。
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号" /> <EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="25sp" />
</TableRow> <TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" > <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="password" /> <EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="25sp" />
</TableRow> <TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content" > <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="取消" /> <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="登录" />
</TableRow>
</LinearLayout> <LinearLayout
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/a2" />
</LinearLayout> <LinearLayout
android:id="@+id/timer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TimePicker
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/timer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TimePicker
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/timer2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TimePicker
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
</RelativeLayout >
</TabHost>
JAVA文件配置
package com.example.tabhost; import android.os.Bundle;
import android.app.Activity;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec; public class MainActivity extends Activity { // 直接继承Activity
private TabHost myTabHost; // 定义TabHost
private int[] layRes = { R.id.login, R.id.image
, R.id.timer, R.id.timer1, R.id.timer2 }; // 定义内嵌布局管理器ID
private int images[]={R.drawable.cart,R.drawable.cloud,R.drawable.comment,R.drawable.gear,R.drawable.joystick};//标题图片数据 @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_main) ; // 调用默认布局管理器
this.myTabHost = (TabHost) super.findViewById(R.id.tabhost); // 取得TabHost对象
this.myTabHost.setup() ; // 建立TabHost对象
for (int x = 0; x < this.layRes.length; x++) { // 循环取出全部布局标记
TabSpec myTab = myTabHost.newTabSpec("tab" + x); // 定义TabSpec
myTab.setIndicator(null,getResources().getDrawable(images[x])) ; // 设置标签文字
myTab.setContent(this.layRes[x]) ; // 设置显示的组件
this.myTabHost.addTab(myTab) ; // 添加标签
}
this.myTabHost.setCurrentTab(0) ; // 设置開始索引
}
}
从零開始学android<TabHost标签组件.二十九.>的更多相关文章
- 从零開始学android<SeekBar滑动组件.二十二.>
拖动条能够由用户自己进行手工的调节,比如:当用户须要调整播放器音量或者是电影的播放进度时都会使用到拖动条,SeekBar类的定义结构例如以下所看到的: java.lang.Object ↳ an ...
- 从零開始学android<Menu菜单组件.三十.>
在Android系统之中.菜单一共同拥有三类:选项菜单(OptionsMenu).上下文菜单(ContextMenu)和子菜单(SubMenu). 今天我们就用几个样例来分别介绍下菜单的使用 acti ...
- 从零開始学android<Bitmap图形组件.四十七.>
android.graphics.Bitmap(位图)是Android手机中专门提供的用于操作图片资源的操作类,使用此类能够直接从资源文件之中进行图片资源的读取.而且对这些图片进行一些简单的改动. 经 ...
- 从零開始学android<数据存储(1)SharedPreferences属性文件.三十五.>
在android中有五种保存数据的方法.各自是: Shared Preferences Store private primitive data in key-value pairs. 相应属性的键值 ...
- 第13章、布局Layouts之RelativeLayout相对布局(从零開始学Android)
RelativeLayout相对布局 RelativeLayout是一种相对布局,控件的位置是依照相对位置来计算的,后一个控件在什么位置依赖于前一个控件的基本位置,是布局最经常使用,也是最灵活的一种布 ...
- 从零開始学android<mediaplayer自带播放器(视频播放).四十九.>
MediaPlayer除了能够对音频播放之外,也能够对视频进行播放,可是假设要播放视频仅仅依靠MediaPlayer还是不够的.还须要编写一个能够用于视频显示的空间,而这块显示空间要求能够高速的进行G ...
- 从零開始学android<ImageSwitcher图片切换组件.二十六.>
ImageSwitcher组件的主要功能是完毕图片的切换显示,比如用户在进行图片浏览的时候.能够通过button点击一张张的切换显示的图片,并且使用ImageSwitcher组件在每次切换的时候也能够 ...
- 从零開始学android<RelativeLayout相对布局.十六.>
相对布局管理器指的是參考某一其它控件进行摆放,能够通过控制,将组件摆放在一个指定參考组件的上.下.左.右等位置,这些能够直接通过各个组件提供的属性完毕. 以下介绍一下各个方法的基本使用 No. 属性名 ...
- 从零開始学android<使用嵌套布局实现计算器界面.十七.>
所谓的嵌套布局就是在一个文件里嵌套多个布局文件 <span style="font-size:18px;"> <LinearLayout android:layo ...
随机推荐
- Photon + Unity3D 线上游戏开发 学习笔记(一)
大家好. 我也是学习Photon + unity3D 的新手 有什么说错的地方大家见谅哈. 我的开发环境是 unity3D 4.1.3 , Visual Studio 是2010 版本号的 p ...
- ORACLE 參数文件介绍
ORACLE数据库启动以后.通过select * from v$parameter这个语句能够查看到oracle数据库使用的全部參数. 对于oracle的參数文件,分为spfile 二进制文件和pfi ...
- C语言:一个涉及指针函数返回值与printf乱码、内存堆栈的经典案例
一个奇怪的C语言问题,涉及到指针.数组.堆栈.以及printf.以下实现: 整数向字符串的转换,返回字符串指针,并在main函数中调用printf显示. #include<stdio.h> ...
- 防火墙设置对外开放port
今天在部署项目时,遇到项目组其它人重整了server上的iis.结果外部訪问不了所部属的项目,通过一些渠道找到了设置方法 例如以下报错的截图: 原因是"入站ICMP规则"被重整了, ...
- 反向Shell增强
下载socat 在客户端: socat file:`tty`,raw,echo=0 tcp-listen:4444 在服务端: socat exec:'bash -li',pty,stderr,set ...
- 两个NSMutableDictionary合并成一个NSMutableDictionary
解决方案: NSMutableDictionary *targetMutableDictionary = [mutableDictionary1 copy]; [targetMutableDictio ...
- ubuntu sublime text 2 破解版
原网地址 : http://blog.csdn.net/icephone/article/details/8217567 关于sublime text 2 的一个使用教程以及前端的不错的学习博客 ht ...
- POJ 2353 DP
双向DP+记录路径. // by SiriusRen #include <stack> #include <cstdio> #include <cstring> u ...
- CaffeNet用于Flickr Style数据集上的风格识别
转自 http://blog.csdn.net/liumaolincycle/article/details/48501423 微调是基于已经学习好的模型的,通过修改结构,从已学习好的模型权重中继续训 ...
- Python3之时间模块详述
Python3之时间模块 time & datetime & calendar 一. 概述 python 提供很多方式处理日期与时间,转换日期格式是一个常见的功能. 时间元组:很多p ...