packagecom.example.tabproject;importandroid.os.Bundle;importandroid.app.Activity;importandroid.app.TabActivity;importandroid.view.LayoutInflater;importandroid.view.Menu;importandroid.widget.TabHost;importandroid.widget.Toast;importandroid.widget.TabHost.OnTabChangeListener;importandroid.widget.TabHost.TabSpec;publicclassMainActivityextendsTabActivityimplementsOnTabChangeListener{privateTabSpects1,ts2,ts3;privateTabHosttableHost;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);tableHost=this.getTabHost();LayoutInflater.from(this).inflate(R.layout.activity_main,tableHost.getTabContentView());ts1=tableHost.newTabSpec("tab1");ts1.setIndicator("tab1");ts1.setContent(R.id.btn);ts2=tableHost.newTabSpec("tab2");ts2.setIndicator("tab2",getResources().getDrawable(R.drawable.bg));ts2.setContent(R.id.et);ts3=tableHost.newTabSpec("tab3");ts3.setContent(R.id.layout);ts3.setIndicator("tab3",getResources().getDrawable(R.drawable.pg2));ts3.setContent(R.id.et);tableHost.addTab(ts1);tableHost.addTab(ts2);tableHost.addTab(ts3);tableHost.setOnTabChangedListener(this);}@OverridepublicbooleanonCreateOptionsMenu(Menumenu){// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main,menu);returntrue;}@OverridepublicvoidonTabChanged(Stringarg0){// TODO Auto-generated method stubif(arg0.equals("tab1")){Toast.makeText(this,"分页1",Toast.LENGTH_LONG).show();}elseif(arg0.equals("tab2")){Toast.makeText(this,"分页2",Toast.LENGTH_LONG).show();}elseif(arg0.equals("tab3")){Toast.makeText(this,"分页3",Toast.LENGTH_LONG).show();}}}