2012-04-04 8 views
0

こんにちは、フラグメントを使用してカスタムタブバー(下部に)を作成して良い例を探しています。サポートパッケージからのフラグメントを使用してタブバーを作成する

私はアクティビティグループを使用してこれを書いていましたが、アンドロイド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); 
} 

たぶん誰かがこれについていくつかの情報を共有することができます:ここで

私は私のカスタムタブバーを作成書いたコードです。

ありがとうございました。

答えて

4

開発者のウェブサイトには、これを行う方法の例がたくさんあります。 FragmentTabs.javaAPI 4+ Support Demosページを参照してください。

ステップバイステップが必要な場合は、これはいいtutorialです。

0

私はあなたのプロジェクトにActionbarsherlockを統合しようとします。 HoneycombとIce Cream Sandwichの新しいTabApiをAndroid 2.xまでのすべてのバージョンで使用できます。本当に簡単にタブを追加できるようになり、あなたのアプリはAndroidのデザインガイドラインに従い、Android Appのように見えます。

+0

私はすでにAction Bar Sherlockを使用しており、タブバーも必要です – Streetboy

関連する問題