2013-05-21 48 views
2

即使它顯示在Eclipse圖形編輯器中,我的TabWidget也不會顯示。我找不到任何理由。爲什麼我的標籤欄不顯示?即使它顯示在ADT編輯器中,TabWidget也不會顯示

的Eclipse

Imgur

模擬器

Imgur

活動的XML源:

http://pastebin.com/Au9XFXPa

從活性提取物從Android的皮棉

結果:

$ lint.bat res/layout/activity_calculator.xml 
Scanning Catalyst: . 
No issues found. 
+0

凡在你的代碼是你,包括'activity_calculator.xml' ? – ozbek

+0

我推薦使用Fragment而不是Tab Widget:D –

+0

@Jeff Lee。它適用於Android版本8+。大多數手機仍然是2.3,這是API 10. – Chloe

回答

5

很難說沒有你的活動是如何實現的實際代碼,但好像你需要調用setContent()TabHost

TabHost tabs = (TabHost)findViewById(R.id.tabhost); 
    tabs.setup(); 

    // Calculator 
    TabHost.TabSpec calculatorTab = tabs.newTabSpec("calculator"); 
    calculatorTab.setContent(R.id.calculator); 
    calculatorTab.setIndicator("Calculator"); 
    tabs.addTab(calculatorTab); 

    // Home 
    TabHost.TabSpec homeTab = tabs.newTabSpec("home"); 
    homeTab.setContent(R.id.home); 
    tabs.addTab(homeTab); 

    // Home 
    TabHost.TabSpec faqTab = tabs.newTabSpec("faq"); 
    faqTab.setContent(R.id.faq); 
    tabs.addTab(faqTab); 

這應該給你這個想法。

+2

謝謝。我很困惑。我認爲它就像其他小部件或GWT圖形編輯器一樣,不需要編程。我清理了答案(tabhost,setIndicator)。 – Chloe

0

嘗試使用FragementsTabHost,這樣的事情:

<TabHost 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" 
      android:orientation="horizontal" /> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:layout_weight="0" /> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/viewpager" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 
    </LinearLayout> 
</TabHost> 

然後初始化選項卡,通過做這樣的事情:

/** 
* Initialise the Tab Host 
*/ 
private void initialiseTabHost(Bundle args) { 
    mTabHost = (TabHost) findViewById(android.R.id.tabhost); 
    mTabHost.setup(); 
    TabInfo tabInfo = null; 
    RedeemActivity.AddTab(this, this.mTabHost, 
      this.mTabHost.newTabSpec("Tab1").setIndicator("1"), 
      (tabInfo = new TabInfo("Tab1", Activity1.class, args))); 
    this.mapTabInfo.put(tabInfo.tag, tabInfo); 
    RedeemActivity.AddTab(this, this.mTabHost, 
      this.mTabHost.newTabSpec("Tab2").setIndicator("2"), 
      (tabInfo = new TabInfo("Tab2", Activity2.class, args))); 
    this.mapTabInfo.put(tabInfo.tag, tabInfo); 
    RedeemActivity.AddTab(this, this.mTabHost, 
      this.mTabHost.newTabSpec("Tab3").setIndicator("3"), 
      (tabInfo = new TabInfo("Tab3", Activity3.class, args))); 
    this.mapTabInfo.put(tabInfo.tag, tabInfo); 
    // Default to first tab 
    // this.onTabChanged("Tab1"); 
    // 
    mTabHost.setOnTabChangedListener(this); 
} 
相關問題