使用TabHost就可以实现我们打电话时经常使用的那个界面了,就是已接来电、未接来电那个。
定义TabHost控件
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- 定义第一个标签页的内容 -->
<LinearLayout
android:id="@+id/tab01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="胡锦涛 - 2012/1/12"
android:textSize="11pt" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="温家宝 - 2012/1/18"
android:textSize="11pt" />
</LinearLayout>
<!-- 定义第二个标签页的内容 -->
<LinearLayout
android:id="@+id/tab02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="孙燕姿 - 2012/1/12"
android:textSize="11pt" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="梁静茹- 2012/1/20"
android:textSize="11pt" />
</LinearLayout>
<!-- 定义第三个标签页的内容 -->
<LinearLayout
android:id="@+id/tab03"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:textSize="11pt" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bill- 2011/09/19"
android:textSize="11pt" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="李开复 - 2011/10/12"
android:textSize="11pt" />
</LinearLayout>
</TabHost>
继承TabActivity,不过这个类目前已经过时了,现在android的提倡使用FragMents。
public class TabHostTest extends TabActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TabHost tabHost = getTabHost();
//设置使用TabHost布局
LayoutInflater.from(this).inflate(R.layout.main,
tabHost.getTabContentView(), true);
//添加第一个标签页
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("已接电话", getResources().getDrawable(R.drawable.take))
.setContent(R.id.tab01));
//添加第二个标签页
tabHost.addTab(tabHost.newTabSpec("tab2")
//在标签标题上放置图标
.setIndicator("呼出电话"
, getResources().getDrawable(R.drawable.callout))
.setContent(R.id.tab02));
//添加第三个标签页
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("未接电话", getResources().getDrawable(R.drawable.untake))
.setContent(R.id.tab03));
}
}