【发布时间】:2014-03-12 11:48:55
【问题描述】:
我在我的应用中使用标签主机作为:
当我单击任何选项卡时,我会移动到另一个活动,如下所示:
当我单击除主选项卡按钮之外的任何选项卡时,我想从屏幕上删除选项卡。这是我的代码:
public class MainActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try{
Resources ressources = getResources();
TabHost tabHost = getTabHost();
// Main tab
Intent intentAndroid = new Intent().setClass(this, DasashboardActivity.class);
TabSpec tabSpecAndroid = tabHost
.newTabSpec("Main")
.setIndicator("Main", ressources.getDrawable(R.drawable.ic_launcher))
.setContent(intentAndroid);
tabHost.clearAllTabs();
// Log tab
Intent intentApple = new Intent().setClass(this, LogActivity.class);
TabSpec tabSpecApple = tabHost
.newTabSpec("Log")
.setIndicator("Log", ressources.getDrawable(R.drawable.ic_action_email))
.setContent(intentApple);
// Settings tab
Intent intentWindows = new Intent().setClass(this, SettingsActivity.class);
TabSpec tabSpecWindows = tabHost
.newTabSpec("Settings")
.setIndicator("Settings", ressources.getDrawable(R.drawable.ic_action_brightness_high))
.setContent(intentWindows);
// Help tab
Intent intentBerry = new Intent().setClass(this, HelpActivity.class);
TabSpec tabSpecBerry = tabHost
.newTabSpec("Help")
.setIndicator("Help", ressources.getDrawable(R.drawable.ic_action_help))
.setContent(intentBerry);
// add all tabs
tabHost.addTab(tabSpecAndroid);
tabHost.addTab(tabSpecApple);
tabHost.addTab(tabSpecWindows);
tabHost.addTab(tabSpecBerry);
//set Windows tab as default (zero based)
tabHost.setCurrentTab(0);
}
catch(Exception ex)
{
Log.e("ERROR in Log class", ex.toString());
}
}
}
如何从其他已启动的活动中删除选项卡?
【问题讨论】:
-
你想达到吗?
标签: android tabs android-tabhost removeall