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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容