package com.zxl;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
public class Activity01 extends TabActivity {
TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab_test1").setIndicator("TAB
1",
getResources().getDrawable(R.drawable.face107)).setContent(
R.id.textView1));
tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator("TAB
2",
getResources().getDrawable(R.drawable.face108)).setContent(
R.id.textView2));
tabHost.addTab(tabHost.newTabSpec("tab_test3").setIndicator("TAB
3",
getResources().getDrawable(R.drawable.face109)).setContent(
R.id.textView3));
tabHost.setBackgroundColor(Color.RED);
tabHost.setBackgroundResource(R.drawable.splash_background);
tabHost.setCurrentTab(0);
tabHost.setOnTabChangedListener(new
OnTabChangeListener() {
AlertDialog.Builder
alertDialog;
@Override
public void
onTabChanged(String tabId) {
//
TODO Auto-rgenerated method stub
alertDialog=new
AlertDialog.Builder(Activity01.this);
alertDialog.setTitle("提示");
alertDialog.setMessage("
当前选中:"+tabId+"标签");
alertDialog.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
@Override
public
void onClick(DialogInterface dialog, int which) {
//
TODO Auto-generated method stub
}
});
alertDialog.create();
alertDialog.show();
}
});
}
layout中布局文件 main.xml
encoding="utf-8"?>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="这是一张切换卡" />
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="这是另一张切换卡" />
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="这是第三张切换卡" />