android 自定义tabhost,android自定义TabHost经典案例.doc

android自定义TabHost经典案例

TabHost案例

1、实现效果

2、实现原理

本实例将实现对TabHost控件的应用,实现原理有:

自定义TabSpace标签

将已经存在的其它Activity窗口当作TabHost的内容显示

3、实现步骤

第一步:创建项目

说明:这里创建一个android项目,名称改了TabHostTestActivity

包名设置为:

第二步:设置布局文档(main.xml)

具体代码如下:

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical"

>

android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:id="@android:id/tabs"

android:layout_width="105dp"

android:layout_height="fill_parent"

android:background="#cccccc"/>

android:id="@android:id/tabcontent"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="1"

android:background="#ffffff"

android:minHeight="365dip" >

第三步:编写Activity窗口代码

(1)创建全局对象

private TabHost tabHost; // 创建TabHost对象

private TabWidget tabWidget; // 创建TabWidget容器对象

public static Context context;private TabSpec Tab1,Tab2,Tab3,Tab4,Tab5,Tab6,Tab7,Tab8;// 标签对象

(2)设置Activity的onCreate方法。

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

context = this;

requestWindowFeature(Window.FEATURE_NO_TITLE); // 不显示系统的标题

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//强制为横屏

setContentView(R.layout.main);makeTab(); // 设置Tab控件的自定义方法

}

(3)创建makeTab()方法,实现对Tab控件的定义设置。

public TabHost makeTab() {

if (this.tabHost == null) {

tabHost = (TabHost) findViewById(android.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值