美文网首页Lee_3do的博客
FragmentActivity FragmentTabHost

FragmentActivity FragmentTabHost

作者: lee_3do | 来源:发表于2015-11-09 12:15 被阅读182次

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

相关文章

网友评论

    本文标题:FragmentActivity FragmentTabHost

    本文链接:https://www.haomeiwen.com/subject/ztqchttx.html