我在我的应用程序中使用选项卡主机作为:

当我单击任何选项卡时,我会移动到另一个活动,如下所示:

当我单击除主选项卡按钮之外的任何选项卡时,我想从屏幕上删除选项卡。下面是我的代码:
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());
}
}
}如何从其他已启动的活动中删除选项卡?
发布于 2014-03-12 20:05:08
您的代码正在调用一个Activity并将Tabs添加到该activity中。例如,请参阅以下内容:
Intent intentBerry = new Intent().setClass(this, HelpActivity.class);
TabSpec tabSpecBerry = tabHost
.newTabSpec("Help")
.setIndicator("Help", ressources.getDrawable(R.drawable.ic_action_help))
.setContent(intentBerry);使用此选项可仅创建活动,但不创建选项卡:
Intent intentBerry = new Intent().setClass(this, HelpActivity.class);
startActivity(intentBerry);发布于 2014-03-12 20:20:16
我不知道你想要什么,但是从tabview中移除标签肯定是不被允许的,这也不好。因此,我建议您禁用选项卡的最好方法,它依赖于其他一些选项卡。例如,用户必须在Tab B之前通过Tab A,然后第一次禁用Tab B,并在观看Tab A内容时启用它。
启用选项卡
findViewById(android.R.id.tabhost).getCurrentTabView().setEnabled(true);禁用选项卡
findViewById(android.R.id.tabhost).getCurrentTabView().setEnabled(false);https://stackoverflow.com/questions/22350573
复制相似问题