繁体   English   中英

如何在Android活动中删除标签

[英]How to remove tabs in Android Activities

我在应用程序中使用制表符主机为: 在此处输入图片说明

当我单击任何选项卡时,我将移至另一个活动,如下所示: 在此处输入图片说明

当我单击除主标签按钮之外的任何标签时,我想从屏幕上删除标签。 这是我的代码:

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());
    }
  }


}

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

您的代码正在调用一个活动,并将Tabs添加到该活动。 例如:

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);

我不知道您想要实现什么,但是从tabview中删除选项卡当然是不允许的,也不是很理想。 因此,我建议您最好禁用与其他选项卡相关的选项卡。 就像用户必须先在Tab B之前浏览Tab A ,然后第一次禁用Tab B并在观看Tab A内容时Tab A其启用。

启用标签

findViewById(android.R.id.tabhost).getCurrentTabView().setEnabled(true);

禁用标签

findViewById(android.R.id.tabhost).getCurrentTabView().setEnabled(false);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM