There is a strange error in my code. I have a TabHost
where I am adding a tab dynamically when a link of the WebView
. I have tested this code on 4.4.2, it works fine. But on 2.3.3 and 2.3.6 and 2.1, it does not work.
I have customized the theme of the tab with a simple xml file.
All code since the tab number 4 that do not change theme look all white.
private void createTab(String url) {
Log.i(TAG, "createTab");
TabHost tabs = getTabHost();
View view = LayoutInflater.from(tabs.getContext()).inflate(
layouts[layoutTab], null);
layoutTab = (layoutTab + 1) % 4;
TabSpec spec = tabs.newTabSpec(Integer.toString(mTabs.getCounter()));
spec.setContent(new MyTabContentFactory(url));
spec.setIndicator(view);
SingleTab st = new SingleTab(tabs.getCurrentTab(), url, spec);
Log.i(DEBUG, st.toString());
mTabs.getList().add(st);
tabs.addTab(spec);
if (tabs.getTabWidget().getChildCount() < 2)
tabs.getTabWidget().getChildAt(0).setVisibility(View.GONE);
else
tabs.getTabWidget().getChildAt(0).setVisibility(View.VISIBLE);
tabs.setCurrentTab(mTabs.getCounter());
mTabs.incrementCounter();
}
Tab implementation in 2.x is buggy and I had difficulty refresing tab after removing a tab from tabhost. There is a fragment tab host implementation in support library which might suit the need.