其效果图:
下面就是创建 Activity类 来实现 其功能:
public class MainActivity extends TabActivity {
public TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 获取对象
tabHost = getTabHost();
TabSpec nearby_tab = tabHost.newTabSpec("nearby_tab");
TabSpec history_tab = tabHost.newTabSpec("history_tab");
TabSpec about_tab = tabHost.newTabSpec("about_tab");
nearby_tab.setIndicator("优酷首页",
getResources().getDrawable(R.drawable.tab_home_selected))
.setContent(new Intent(this, MyCenterActivity.class));
history_tab.setIndicator("频道中心",
getResources().getDrawable(R.drawable.tab_category_selected))
.setContent(new Intent(this, MyIndexActivity.class));
about_tab.setIndicator("个人中心",
getResources().getDrawable(R.drawable.tab_usercenter_select))
.setContent(new Intent(this, MySelfActivity.class));
tabHost.addTab(nearby_tab);
tabHost.addTab(history_tab);
tabHost.addTab(about_tab);
}
@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;
}
}