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的類.