public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = (TabHost) findViewById(R.id.tabhostscreen_tabhost);
mLocalActivityManager = new LocalActivityManager(this, false);
tabHost.setup(mLocalActivityManager);
mLocalActivityManager.dispatchCreate(savedInstanceState); //after the tab's setup is called, you have to call this or it wont work
TabHost.TabSpec spec;
Intent intent;
//set up your tabs here. It's easy to just do seperate activities for each tab, and link them in here.
intent = new Intent().setClass(this, SomeActivity.class);
spec = tabHost.newTabSpec("tagname1").setIndicator("tab indicator 1", getResources().getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SomeOtherActivity.class);
spec = tabHost.newTabSpec("tagname2").setIndicator("tab indicator 2").setContent(intent);
tabHost.addTab(spec);
}
我可以将额外内容添加到这些标签中,如果是真的,怎么做?
答案 0 :(得分:0)
是的,你可以加入额外的东西。做这样的事情:
intent = new Intent().setClass(this, SomeActivity.class);
intent.putExtra("this_is_my_extra", "hello world!");
spec = tabHost.newTabSpec("tagname1").setIndicator( ... );
spec.setContent(intent);
tabHost.addTab(spec);