近期剛學(xué)了Fragment,突然想在Fragment中實(shí)現(xiàn)TabHost,查閱相關(guān)資料后發(fā)現(xiàn)現(xiàn)在TabHost已經(jīng)被FragmentTabHost替代了,因此就想著學(xué)習(xí)一下,并記錄下來,接下來把一些心得分享一下。
一、使用場景
首先FragmentTabHost不僅可以在FragmentActivity中使用,也可以在Fragment中使用,通過與Fragment的結(jié)合實(shí)現(xiàn)TabHost的效果
二、使用步驟
1、布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</RelativeLayout>
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;
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)站名稱:關(guān)于FragmentTabHost的使用-創(chuàng)新互聯(lián)
標(biāo)題來源:http://chinadenli.net/article12/diosdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、網(wǎng)站策劃、外貿(mào)建站、標(biāo)簽優(yōu)化、云服務(wù)器、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容