TabActivity和TabHost+Fragment和FragmentTabHost的区别
答案:2 悬赏:0 手机版
解决时间 2021-03-03 06:34
- 提问者网友:城市野鹿
- 2021-03-02 19:29
TabActivity和TabHost+Fragment和FragmentTabHost的区别
最佳答案
- 五星知识达人网友:掌灯师
- 2021-03-02 19:57
//定义FragmentTabHost对象
private MyFragmentTabHost mTabHost;
//定义数组来存放Fragment界面
private Class fragmentArray[] = {BaseFragment.class,BaseFragment.class,BaseFragment.class,BaseFragment.class,BaseFragment.class};
//Tab选项卡的文字
private String mTextviewArray[] = {"a", "b", "c", "d", "e"};
//实例化TabHost对象,得到TabHost
mTabHost = (SunnyFragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
//得到fragment的个数
int count = fragmentArray.length;
for(int i = 0; i < count; i++){
//为每一个Tab按钮设置图标、文字和内容
TabHost.TabSpec tabSpec = mTabHost.newTabSpec(mTextviewArray[i]).setIndicator(getTabItemView(i));
//将Tab按钮添加进Tab选项卡中
mTabHost.addTab(tabSpec, fragmentArray[i], null);
//设置Fragment的背景
BaseFragment bf = (BaseFragment)getSupportFragmentManager().findFragmentByTag(mTextviewArray[i]);
if(bf!=null)
private MyFragmentTabHost mTabHost;
//定义数组来存放Fragment界面
private Class fragmentArray[] = {BaseFragment.class,BaseFragment.class,BaseFragment.class,BaseFragment.class,BaseFragment.class};
//Tab选项卡的文字
private String mTextviewArray[] = {"a", "b", "c", "d", "e"};
//实例化TabHost对象,得到TabHost
mTabHost = (SunnyFragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
//得到fragment的个数
int count = fragmentArray.length;
for(int i = 0; i < count; i++){
//为每一个Tab按钮设置图标、文字和内容
TabHost.TabSpec tabSpec = mTabHost.newTabSpec(mTextviewArray[i]).setIndicator(getTabItemView(i));
//将Tab按钮添加进Tab选项卡中
mTabHost.addTab(tabSpec, fragmentArray[i], null);
//设置Fragment的背景
BaseFragment bf = (BaseFragment)getSupportFragmentManager().findFragmentByTag(mTextviewArray[i]);
if(bf!=null)
全部回答
- 1楼网友:思契十里
- 2021-03-02 21:36
有什么问题吗?
我可以帮你看看,我们项目中用过这种架构
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯