我在我的应用中使用标签主机:
当我点击任何标签时,我会移动到另一个活动,如下所示:
当我点击除主标签按钮以外的任何标签时,我想从屏幕中删除标签。这是我的代码:
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());
}
}
}
如何从其他已启动的活动中删除标签?
答案 0 :(得分:0)
您的代码正在调用一个活动并将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);
答案 1 :(得分:0)
我不知道你想要实现什么,但是从tabview中删除标签当然是不允许的,也不是很好。所以我建议您禁用与某些其他标签相关的标签的最佳方式。就像用户必须在Tab A
之前通过Tab B
一样,然后首次禁用Tab B
并在观看Tab A
内容时启用它。
启用标签
findViewById(android.R.id.tabhost).getCurrentTabView().setEnabled(true);
停用标签
findViewById(android.R.id.tabhost).getCurrentTabView().setEnabled(false);