FragmentActivity FragmentTabHost

FragmentActivity FragmentTabHost配合使用,可以實現類似微博微信一樣的下方切換狀態欄.
類似如下:



布局如下,重點是設置tabhost,tabcontent兩個組件.

<HomeTabHost
    android:id="@android:id/tabhost">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
        <View 
            android:layout_width="match_parent"
            android:layout_height="1dip"
            android:background="@color/home_tab_divider_backgound" />
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="@dimen/home_tab_height"
            android:background="@drawable/tw_list_pressed_holo" />
    </LinearLayout>

</.HomeTabHost>

代碼中找到tabhost后,調用setup方法構建:

    mHomeTabHost = (HomeTabHost) findViewById(android.R.id.tabhost);
    mHomeTabHost.setup(this, getSupportFragmentManager(),android.R.id.tabcontent);

最后為tabhost添加子Fragment:

mHomeTabHost.addTab(mHomeTabHost.newTabSpec(mTabTag.get(i))
                    .setIndicator(view), mTabClassList.get(i),
                    savedInstanceState);

view為每個按鈕(Indicator)的view,第二個參數為Fragment的類.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容