0

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

以前はアクティビティ グループを使用してこれを記述していましたが、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);
}

多分誰かがこれについての情報を共有することができます.

ありがとう。

4

2 に答える 2

4

開発者の Web サイトには、これを行う方法の例がたくさんあります。FragmentTabs.java、およびAPI 4+ サポート デモページを参照してください。

ステップバイステップが必要な場合、これも素晴らしいチュートリアルです。

于 2012-04-04T06:03:38.207 に答える
0

Actionbarsherlockをあなたのプロジェクトに統合してみます。Android 2.x までのすべてのバージョンで、Honeycomb および Ice Cream Sandwich の新しい TabApi を使用できます。これにより、タブの追加が非常に簡単になり、アプリは Android デザイン ガイドラインに準拠し、Android アプリのように見えます。

于 2012-04-04T06:14:39.207 に答える