我在使用TabHost并在标签之间切换时遇到问题。我已将标签放在底部,并为每个标签提供了单独的意图,如下所示: -
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
intent = new Intent().setClass(this,BottomTabs.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("search").setIndicator("Home",
res.getDrawable(R.drawable.home))
.setContent(intent);
tabHost.addTab(spec);
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this,BottomTabWebsite.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("search").setIndicator("Website",
res.getDrawable(R.drawable.website1))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MSIDates.class);
spec = tabHost.newTabSpec("social").setIndicator("Dates",
res.getDrawable(R.drawable.memory_lane))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, BottomTabExit.class);
spec = tabHost.newTabSpec("contact").setIndicator("Exit",
res.getDrawable(R.drawable.exit))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
从1个标签切换到另一个标签时没有,下一个标签的内容显示在前一个标签的内容正下方。简而言之,第一个标签的内容不会被清除。虽然我已将与下一个选项卡相关的活动的内容视图设置为其他布局。我需要注意什么,以确保早期标签的内容被选中的标签内容覆盖?