或者用 new Intent 来引入其他Activity的内容: setContent(Intent intent)
public class JianYan_Tab extends ActivityGroup {
public static final String CHAXUN_TAB = "chaxun";
public static final String GUANLI_TAB = "guanli";
public static TabHost mTabHost;//tabhost是一个标签的载体
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.jiwu_jianyan_tab);
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this.getLocalActivityManager());
mTabHost.addTab(mTabHost.newTabSpec(CHAXUN_TAB)
//用这个语句添加一个标签
.setIndicator(buildIndicator(R.string.tabchaxun))//
这里用的是指定某个view : setIndicator (View view)
buildIndicator是view类型。后面有定义
我理解这里的 Indicator 就是Tab上的label,它可以
设置label : setIndicator (CharSequence label)
或者同时 设置label和icon : setIndicator (CharSequence label, Drawable icon)
或者直接 指定某个view : setIndicator (View view)
对于 Content ,就是Tab里面的内容,可以
设置View的id : setContent(int viewId)
或者 TabHost.TabContentFactory 的createTabContent(String tag)来处 理: setContent(TabHost.TabContentFactory contentFactory)
或者用 new Intent 来引入其他Activity的内容: setContent(Intent intent)
mTabHost.addTab(mTabHost.newTabSpec(GUANLI_TAB)
.setIndicator(buildIndicator(R.string.tabguanli))
.setContent(new Intent(JianYan_Tab.this, JianYan_Mana.class)));
mTabHost.setCurrentTab(0);
}
private View buildIndicator(int textRes) {
final TextView indicator = (TextView) getLayoutInflater().inflate(
R.layout.tab_indicator,
(ViewGroup) findViewById(android.R.id.tabs), false);
indicator.setText(textRes);
return indicator;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// 获取当前活动的Activity实例
Activity subActivity = getLocalActivityManager().getCurrentActivity();
//判断是否实现返回值接口
if (subActivity instanceof OnTabActivityResultListener) {
//获取返回值接口实例
OnTabActivityResultListener listener = (OnTabActivityResultListener) subActivity;
//转发请求到子Activity
listener.onTabActivityResult(requestCode, resultCode, data);
}
super.onActivityResult(requestCode, resultCode, data);
}
}