下面列出了怎么用android.widget.TabHost.TabContentFactory的API类实例代码及写法,或者点击链接到github查看源代码。
private void initTabs() {
MainTab[] tabs = MainTab.values();
final int size = tabs.length;
for (int i = 0; i < size; i++) {
MainTab mainTab = tabs[i];
TabSpec tab = mTabHost.newTabSpec(getString(mainTab.getResName()));
View indicator = LayoutInflater.from(getApplicationContext())
.inflate(R.layout.tab_indicator, null);
TextView title = (TextView) indicator.findViewById(R.id.tab_title);
Drawable drawable = this.getResources().getDrawable(
mainTab.getResIcon());
title.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null,
null);
title.setText(getString(mainTab.getResName()));
tab.setIndicator(indicator);
tab.setContent(new TabContentFactory() {
@Override
public View createTabContent(String tag) {
return new View(MainActivity.this);
}
});
mTabHost.addTab(tab, mainTab.getClz(), null);
mTabHost.getTabWidget().getChildAt(i).setOnTouchListener(this);
}
}