TabHostProject 标签的使用(方法一)
来源:互联网 发布:定型喷雾哪个好 知乎 编辑:程序博客网 时间:2024/06/01 15:08
标签的使用方式
如果想实现这种标签的显示界面,有两种方式
方式一、直接让一个Activity程序继承TabActivity
1、如果一个程序Activity程序继承了TabActivity类,则直接可以利用getTabHost()方法就可以取得一个TabHost类的对象
2、在标签界面显示的时候,由于现在不是通过<TabHost>元素在布局管理器中定义组件形式,无法使用findViewById()方法进行TabHost对象的实例化,那么就可以通过LayoutInflater类完成布局管理器中定义组件的实例化操作(将布局管理器设置到某个容器中)
主程序MyTabHostDemo
package com.jackie.tabhostproject;
import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MyTabHostDemo extends TabActivity {
private TabHost myTabHost = null;
private int[] layRes = new int[] { R.id.tab_edit, R.id.tab_clock,
R.id.tab_sex };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.myTabHost = super.getTabHost(); // 取得TabHost对象
LayoutInflater.from(this).inflate(R.layout.tab,
this.myTabHost.getTabContentView(), true); //true表示实例化布局中的组件
for(int x=0;x<this.layRes.length;x++){
TabSpec myTab=this.myTabHost.newTabSpec("tab"+x); //"tab"+x 所需的选项卡标签(tag)
myTab.setIndicator("标签-"+x); //设置每个子标签的名字
myTab.setContent(this.layRes[x]);
this.myTabHost.addTab(myTab);
}
}
}
import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MyTabHostDemo extends TabActivity {
private TabHost myTabHost = null;
private int[] layRes = new int[] { R.id.tab_edit, R.id.tab_clock,
R.id.tab_sex };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.myTabHost = super.getTabHost(); // 取得TabHost对象
LayoutInflater.from(this).inflate(R.layout.tab,
this.myTabHost.getTabContentView(), true); //true表示实例化布局中的组件
for(int x=0;x<this.layRes.length;x++){
TabSpec myTab=this.myTabHost.newTabSpec("tab"+x); //"tab"+x 所需的选项卡标签(tag)
myTab.setIndicator("标签-"+x); //设置每个子标签的名字
myTab.setContent(this.layRes[x]);
this.myTabHost.addTab(myTab);
}
}
}
自定义的子标签线性布局tab.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/tab_edit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请输入搜索关键字。。。"
android:textSize="18px" />
<Button
android:id="@+id/myBut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜索" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab_clock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<AnalogClock
android:id="@+id/myAnalogClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab_sex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/male"
android:checked="true"
android:text="性别:男" />
<RadioButton
android:id="@+id/female"
android:text="性别:女" />
"
</RadioGroup>
</LinearLayout>
</LinearLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/tab_edit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请输入搜索关键字。。。"
android:textSize="18px" />
<Button
android:id="@+id/myBut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜索" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab_clock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<AnalogClock
android:id="@+id/myAnalogClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab_sex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/male"
android:checked="true"
android:text="性别:男" />
<RadioButton
android:id="@+id/female"
android:text="性别:女" />
"
</RadioGroup>
</LinearLayout>
</LinearLayout>
0 0
- TabHostProject 标签的使用(方法一)
- TabHostProject 标签的使用(方法二 配置文件)
- struts2标签的使用(一)
- html标签的使用(一)
- 前端知识之标签的使用一
- HTML基本标签的使用(一)
- 使用Struts2的标签库(一)
- struts-struts标签的使用(一)
- HTML中使用struts标签的方法
- struts2标签使用css的方法
- struct2标签使用一
- 用 jsp 定制标签创建超连接的方法(一)
- mybatis的动态SQL(一)if标签的使用
- mybatis 之 动态sql(一)choose标签的使用
- Struts2标签使用一特例
- shiro 标签使用(一)
- 使用递归的方法获得项目的标签
- Android之Tab分页标签的实现方法一-----TabActivity和TabHost的结合(一)
- dump文件抓取方法
- 有关vector数组的用法
- iOS 修改UIView位置和大小的方式
- CentOS5中快速搭建ftp服务器
- (Android)Unable to resolve target 'android-15'
- TabHostProject 标签的使用(方法一)
- dmp导出imp导入
- HDU 2002 计算球体积
- 找到链表的倒数第m个节点
- 三维图像技术与OpenGL基础理论
- 在Eclipse中进行C/C++开发的配置方法(20140721最新版)
- 《ArchSummit深圳2014大会》所见所闻小结
- Java集合源码学习(16)_BlockingQueue接口的实现ArrayBlockingQueue
- sql注入在线检测(sqlmapapi)