package com.isoftstone.cry;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;
public class TabActivityTest extends TabActivity
{
private TabHost tabHost ;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
tabHost = getTabHost();
//LayoutInflater是用来找layout下xml布局文件,并且实例化
LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.framelayout,tabHost.getTabContentView(),true);
// LayoutInflater.from(this).inflate(R.layout.framelayout,tabHost.getTabContentView(),true);
tabHost.addTab(tabHost.newTabSpec("all").setIndicator("所有通话记录")
.setContent(R.id.tabHosttextView1));
tabHost.addTab(tabHost.newTabSpec("ok").setIndicator("已接来电")
.setContent(R.id.tabHosttextView2));
tabHost.addTab(tabHost.newTabSpec("canncel")
.setIndicator("未接来电").setContent(R.id.tabHosttextView3));
// 不引用xml tabhost,可自定义设置视图
// setContentView(tabHost);
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/framelayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TabHost
android:id="@+id/tabhost01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TabHost>
<TextView
android:id="@+id/tabHosttextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="所有通话记录tab" />
<TextView
android:id="@+id/tabHosttextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="已接来电tab" />
<TextView
android:id="@+id/tabHosttextView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="未接来电tab" />
</FrameLayout>