2012-04-04 107 views
0

您好,我正在使用片段搜索創建自定義選項卡欄(位於底部)的一個很好的示例。使用支持包中的片段創建選項卡欄

早些時候我已經使用Activities Groups編寫過這個,但是從android 3. *它已經被棄用了,我需要使用片段來做到這一點。

這裏是我寫的創建我的自定義標籤欄的代碼:

private void setTabs() 
{ 

    //Implementing strings 
    String publication = String.format("First"); 
    String shop = String.format("Second"); 

    //Adding tabs to TabActivity 
    //addTab(publication, R.drawable.ic_launcher, DisplayTestActivity.class); 
    //addTab(shop, R.drawable.ic_launcher, DisplayPushedTestActivity.class); 



} 


@Override 
public void onTabChanged(String tabId) { 
    // TODO Auto-generated method stub 

} 

/** 
* 
* @param labelId, tab name 
* @param drawableId, tab icon image 
* @param c, responsible class 
*/ 
/* 
private void addTab(String labelId, int drawableId, Class<?> c) 
{ 
    TabHost tabHost = getTabHost(); // The activity TabHost 

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

    System.out.println(tabIndicator); 

    TextView title = (TextView) tabIndicator.findViewById(R.id.tab_bar_title); 

    System.out.println(labelId); 
    System.out.println(title); 
    title.setText(labelId); 
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.tab_bar_icon); 
    icon.setImageResource(drawableId); 

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

也許有人可以分享一些這方面的信息。

謝謝。

回答

0

我會嘗試將Actionbarsherlock整合到您的項目中。它使您可以使用Honeycomb和Ice Cream Sandwich中的新TabApi,所有版本的Android 2.x.它使添加選項卡變得非常簡單,您的應用將遵循Android設計指南,並且看起來像一個Android應用。

+0

我已經在使用Action Bar Sherlock,並且還希望標籤欄 – Streetboy 2012-04-04 06:16:09

相關問題