package com.task.apptaobao; import android.os.Bundle; import android.app.TabActivity; import android.content.Intent; import android.view.Menu; import android.widget.TabHost; import android.widget.TabHost.TabSpec; public class MainActivity extends TabActivity { private TabHost _tabHost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); _tabHost = getTabHost(); AddTabPage1(); AddTabPage2(); AddTabPage3(); AddTabPage4(); AddTabPage5(); } private void AddTabPage5() { Intent internt5 = new Intent(); internt5.setClass(this, ACT5.class); TabSpec tabSpec = _tabHost.newTabSpec("act5"); // TODO Auto-generated method stub tabSpec.setIndicator("更多"); // 指定跳转方向 tabSpec.setContent(internt5); _tabHost.addTab(tabSpec); } private void AddTabPage4() { // TODO Auto-generated method stub Intent internt4 = new Intent(); internt4.setClass(this, ACT4.class); TabSpec tabSpec = _tabHost.newTabSpec("act4"); tabSpec.setIndicator("分享"); // 指定跳转方向 tabSpec.setContent(internt4); _tabHost.addTab(tabSpec); } private void AddTabPage3() { // TODO Auto-generated method stub Intent internt3 = new Intent(); internt3.setClass(this, ACT3.class); TabSpec tabSpec = _tabHost.newTabSpec("act3"); tabSpec.setIndicator("购物车"); // 指定跳转方向 tabSpec.setContent(internt3); _tabHost.addTab(tabSpec); } private void AddTabPage2() { // TODO Auto-generated method stub Intent internt2 = new Intent(); internt2.setClass(this, ACT2.class); TabSpec tabSpec = _tabHost.newTabSpec("act2"); tabSpec.setIndicator("我的"); // 指定跳转方向 tabSpec.setContent(internt2); _tabHost.addTab(tabSpec); } private void AddTabPage1() { // TODO Auto-generated method stub Intent internt1 = new Intent(); internt1.setClass(this, HomeActivity.class); TabSpec tabSpec = _tabHost.newTabSpec("home"); // 指定选项卡的显示名称 tabSpec.setIndicator("首页"); // 指定跳转方向 tabSpec.setContent(internt1); _tabHost.addTab(tabSpec); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
评论