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