Android中TabHost部件使用

来源:互联网 发布:网络电视直播客户端 编辑:程序博客网 时间:2024/05/15 23:47

其效果图:

下面就是创建 Activity类 来实现 其功能:

public class MainActivity extends TabActivity {public TabHost tabHost;@Overrideprotected 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);}@Overridepublic 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;}}