我自定义了tabs,可是不知道如何给tabs添加内容content。我甚至不知道从哪里开始编写添加内容的代码。
这是我设置content内容的代码
private void setupTab(final View view, final String tag) {
View tabview = createTabView(mTabHost.getContext(), tag);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
public View createTabContent(String tag) {return view;}
});
mTabHost.addTab(setContent);
}
但是再如何处理TabContentFactory
呢?
1.) public class CustomTabActivity extends Activity
,我把它改成 extend TabActivity
2.) 使用 Intent添加 content
Intent intent = new Intent().setClass(this, Hello.class);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent);
看这段代码:
private void addActivityTab(int labelResId, int iconResId, Intent intent) {
String tabLabel = getString(labelResId);
View indicator = View.inflate(this, R.layout.simple_tab_spec, null);
ImageView icon = (ImageView) indicator.findViewById(R.id.simple_tab_spec_icon);
icon.setImageResource(iconResId);
TabSpec tabSpec = tabHost.newTabSpec(tabLabel).setIndicator(indicator).setContent(intent);
tabHost.addTab(tabSpec); }
第一个参数是 tab 选项的标题。第二个参数是 tab 项的背景图像。你应该创建一个intent对象来设置参数和目标活动。