首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何删除Android活动中的选项卡

如何删除Android活动中的选项卡
EN

Stack Overflow用户
提问于 2014-03-12 19:48:55
回答 2查看 795关注 0票数 0

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

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

当我单击除主选项卡按钮之外的任何选项卡时,我想从屏幕上删除选项卡。下面是我的代码:

代码语言:javascript
复制
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());
    }
  }


}

如何从其他已启动的活动中删除选项卡?

EN

回答 2

Stack Overflow用户

发布于 2014-03-12 20:05:08

您的代码正在调用一个Activity并将Tabs添加到该activity中。例如,请参阅以下内容:

代码语言:javascript
复制
Intent intentBerry = new Intent().setClass(this, HelpActivity.class);
TabSpec tabSpecBerry = tabHost
    .newTabSpec("Help")
    .setIndicator("Help", ressources.getDrawable(R.drawable.ic_action_help))
    .setContent(intentBerry);

使用此选项可仅创建活动,但不创建选项卡:

代码语言:javascript
复制
Intent intentBerry = new Intent().setClass(this, HelpActivity.class);
startActivity(intentBerry);
票数 0
EN

Stack Overflow用户

发布于 2014-03-12 20:20:16

我不知道你想要什么,但是从tabview中移除标签肯定是不被允许的,这也不好。因此,我建议您禁用选项卡的最好方法,它依赖于其他一些选项卡。例如,用户必须在Tab B之前通过Tab A,然后第一次禁用Tab B,并在观看Tab A内容时启用它。

启用选项卡

代码语言:javascript
复制
findViewById(android.R.id.tabhost).getCurrentTabView().setEnabled(true);

禁用选项卡

代码语言:javascript
复制
findViewById(android.R.id.tabhost).getCurrentTabView().setEnabled(false);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22350573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档