资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

关于FragmentTabHost的使用

    近期刚学了Fragment,突然想在Fragment中实现TabHost,查阅相关资料后发现现在TabHost已经被FragmentTabHost替代了,因此就想着学习一下,并记录下来,接下来把一些心得分享一下。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名与空间、虚拟空间、营销软件、网站建设、忻州网站维护、网站推广。

一、使用场景

    首先FragmentTabHost不仅可以在FragmentActivity中使用,也可以在Fragment中使用,通过与Fragment的结合实现TabHost的效果

二、使用步骤

    1、布局文件  

    

    

        xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="match_parent"

        android:layout_height="match_parent" >

    

       

        android:id="@android:id/tabhost"

        android:layout_width="match_parent"

        android:layout_height="wrap_content">

    

        

                android:layout_width="match_parent"

                android:layout_height="match_parent"

                android:orientation="vertical" >

    

               

                    android:id="@android:id/tabs"

                    android:layout_width="match_parent"

                    android:layout_height="wrap_content"

                    android:layout_weight="0"

                    android:orientation="horizontal" />

    

               

                    android:id="@android:id/tabcontent"

                    android:layout_width="0dp"

                    android:layout_height="0dp"

                    android:layout_weight="0" />

    

               

                    android:id="@+id/realtabcontent"

                    android:layout_width="match_parent"

                    android:layout_height="0dp"

                    android:layout_weight="1" />

           

       

    

    2、代码:

        1)继承FragmentActivity——OnCreate()中:

            FragmentTabHost fragmentTabHost =                                                                                      (FragmentTabHost)findViewById(android.R.id.tabhost);

            fragmentTabHost.setup(this, getFragmentManager(), R.id.realtabcontent);

            fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab1").setIndicator("我的意                                         见"), SettingFragment.class, null);

            fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab2").setIndicator("常见问                                         题"), NotificationFragment.class, null);

        2)继承Fragment——OnCreateView()中:

             View layout = inflater.inflate(R.layout.fragment_sliding_feedback, null);

             FragmentTabHost fragmentTabHost =                                                                             (FragmentTabHost)layout.findViewById(android.R.id.tabhost);

            fragmentTabHost.setup(this, getChildFragmentManager(), R.id.realtabcontent);

            fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab1").setIndicator("我的意                                         见"), SettingFragment.class, null);

            fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab2").setIndicator("常见问                                         题"), NotificationFragment.class, null);

            return layout;

    


文章名称:关于FragmentTabHost的使用
文章地址:http://cdkjz.cn/article/jseced.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220