Tabactivity当中已经有了自己的tab,他不需要解析一个XML文件,可以通过gethost()方法获取tabhost。事例代码如下:
@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//注意这里没有解析XML文件的方法,而是 通过gettabhost获取了一个tab
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost
.newTabSpec("tab1")
.setIndicator("已结电话",
getResources().getDrawable(R.drawable.ic_launcher))
.setContent(new Intent(this, Test1.class)));
tabHost.addTab(tabHost
.newTabSpec("tab2")
.setIndicator("结电话",
getResources().getDrawable(R.drawable.ic_launcher))
.setContent(new Intent(this, Test2.class)));
tabHost.addTab(tabHost
.newTabSpec("tab3")
.setIndicator("电话",
getResources().getDrawable(R.drawable.ic_launcher))
.setContent(new Intent(this, Test3.class)));
}
}
另外使用这种方式,可建立3个activity,这样在有的情况下就不会使一个文件的代码量变得庞杂。