2014-09-02 28 views
0

我正在使用此代碼在android中放置底部的標籤欄,但它不會出現在我的佈局頁面中的應用程序。我也在drawable中創建了maintab.xml和其他選項卡所需的文件。但仍然無效。你能告訴我什麼是錯的嗎?如何在android中製作底部的標籤欄?

public class TabbottonActivity extends TabActivity { 
    /** Called when the activity is first created. */ 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.maintab); 
     setTabs() ; 
    } 
    private void setTabs() 
    { 
     addTab("Home", R.drawable.tab_home, MenuActivity.class); 
     addTab("Search", R.drawable.tab_search, DestinationActivity.class); 

     addTab("Home", R.drawable.tab_home, MenuActivity.class); 
     addTab("Search", R.drawable.tab_search, DestinationActivity.class); 
    } 

    private void addTab(String labelId, int drawableId, Class<?> c) 
    { 
     TabHost tabHost = getTabHost(); 
     Intent intent = new Intent(this, c); 
     TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

     View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false); 
     TextView title = (TextView) tabIndicator.findViewById(R.id.title); 
     title.setText(labelId); 
     ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); 
     icon.setImageResource(drawableId); 

     spec.setIndicator(tabIndicator); 
     spec.setContent(intent); 
     tabHost.addTab(spec); 
    } 
} 

回答

1

不要使用底部的標籤欄

不要使用底部的標籤欄 Tther平臺使用底部的標籤欄應用程序的視圖之間切換。按照平臺約定,Android的視圖控制選項卡將顯示在屏幕頂部的操作欄中。另外,Android應用程序可能會使用底部欄來顯示拆分操作欄上的操作。

您應該遵循本指南,在Android平臺上與其他應用創建一致的體驗 ,以避免 操作與Android上的視圖切換混淆。

來源:http://developer.android.com/design/patterns/pure-android.html

編輯: 你應該如何創建標籤

http://developer.android.com/training/implementing-navigation/lateral.html

+0

但原代碼工作正常,但是當我用我的應用程序集成它它不工作! – Anita 2014-09-02 20:04:05

+0

確保佈局文件(maintab.xml)中沒有錯誤。 – 2014-09-02 20:06:34

+0

一切都一樣我只是改變了我想要的類,例如在家中點擊後顯示的類。這些行被改變: addTab(「Home」,R.drawable.tab_home,MenuActivity.class); addTab(「Search」,R.drawable.tab_search,DestinationActivity.class); – Anita 2014-09-02 20:36:39

相關問題