2012-04-17 7 views
0

タブバー付きのアプリを開発する必要がありますが、タブレットとフラグメントの使用方法を示すAndroidドキュメントのFragmentsには多くの問題があります。
何も表示されていないので、すべてのタブスタックで正しく行う方法についてです。Androidアプリ用のカスタムタブバーを描画する

私はtab1に行くことができるので、それは開いているフラグメントAです。次に、フラグメントBを深く開いて、タブをtab2に切り替えて、同じフラグメントBをtab1に戻して切り替えることができます。

各タブごとにFragmentActivityを作成するソリューションがいくつかありますが、その管理では廃止予定のTabActivityを使用する必要があります。

タブバーを描画してすべてのレイアウトに配置でき、ユーザーがタブバーのボタンを押すたびにアクティビティを開始できますか?

もしこれが実現できたのであれば、これを実装したか、またはチュートリアルを描く方法や、これを使うことができますか?

ありがとうございました。あなたはこのコード

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout android:orientation="vertical" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <FrameLayout android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" android:layout_height="0dip" 
     android:layout_weight="1" /> 

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

そして、Activityクラスでの追加のXML down_tabs.xmlで

答えて

4

私はそれが正常に動作しますことを願っています

public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.down_tabs); 
    initTabs(); 
} 

private void initTabs() { 
    // Set Calendar Tab 
    // getTabWidget().setDividerDrawable(R.drawable.tab_divider); 
    getTabWidget().setPadding(0, 0, 0, 0); 
    addTab("", R.drawable.home_tab_drawable, CalendarUIActivity.class); 
    addTab("", R.drawable.lucky_dates_drawable, LuckyDatesActivity.class); 
    addTab("", R.drawable.life_stages_drawable, LifeStagesActivity.class); 
    addTab("", R.drawable.find_items_drawable, FindItemsActivity.class); 
    addTab("", R.drawable.more_tab_drawable, MoreActivity.class); 
} 

private void addTab(String labelId, int drawableId, Class<?> targetClass) { 
    TabHost tabHost = getTabHost(); 
    Intent intent = new Intent(this, targetClass); 
    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); 

    tabIndicator.setBackgroundResource(R.drawable.tab_backgroud); 
    // ////////// 
    spec.setIndicator(tabIndicator); 
    spec.setContent(intent); 
    tabHost.addTab(spec); 

} 

、とタブの仕様を追加します。

+0

完全なチュートリアルの訪問のため..

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" /> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0" /> </LinearLayout> </TabHost> 

知っwork..uするのは簡単です代わりにフラグメントを使用する必要があります。私は今このアプローチをしていますが、それは私に合っていません。しかし、ありがとう。 – Streetboy

+0

すてきな回答ありがとう!!!! –

関連する問題