4
我需要以编程方式“按需”创建所有UI,这意味着我无法使用任何XML。这是我做的伪代码:了解活动的setContentView
View v = new MyView();
activity.setContentView(v);
tabHost = new TabHost();
....
tabHost.setup();
TabSpec tabSpec = _tabHost.newTabSpec(page);
tabSpec.setIndicator(title);
tabSpec.setContent((TabContentFactory) this);
activity.setContentView(tabHost);
所以当TabContentFactory叫我回到这是当前活动的内容视图的视图。基本上我所做的是采用当前视图并将其包装在tabhost中。 它的一半工作,当我这样做时,我能够看到tabbar,但只有黑色视图下面,如果我点击其他选项卡,然后点击返回,然后我可以看到视图,一切按预期工作。
现在为什么我认为这是关系到setContentView
,因为当我这样做:
View v = new MyView();
// activity.setContentView(v); // we don't use it as current content view
tabHost = new TabHost();
....
tabHost.setup();
TabSpec tabSpec = _tabHost.newTabSpec(page);
tabSpec.setIndicator(title);
tabSpec.setContent((TabContentFactory) this);
那么一切都可以正常使用。 任何帮助表示感谢,谢谢!