2014-03-12 47 views
0

我使用的標籤主機在我的應用程序爲:enter image description here如何刪除選項卡中的Android活動

當我我移動到另一個活動的任何選項卡上單擊如下: enter image description here

我想刪除標籤從屏幕上點擊除主選項卡按鈕以外的任何選項卡。以下是我的代碼:

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

重量ü要才達到? – Sush

回答

0

您的代碼正在調用一個活動並將選項卡添加到活動中。例如看到這一點:

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

謝謝ElectronicGeek :) – user3381979

0

我不知道你想達到什麼樣的,但是從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); 
+0

當我點擊任何標籤,即如果我點擊幫助,那麼不應該有幫助活動頂部的標籤,sush我不知道該怎麼做:| – user3381979

+0

@ user3381979標籤並不意味着這一點,即當其他標籤被點擊時消失,但是你可以禁用某些標籤進行某些特定的驗證。 – Sush

相關問題