本篇文章為大家展示了Android中怎么實(shí)現(xiàn)選項(xiàng)卡功能,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
贛州ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!
首先創(chuàng)建Android工程命名自己的Activity為HelloTabWidget
在main.xml或者自己定義的*.xml文件中創(chuàng)建一個TabHost,需要兩個元素TabWidget和FrameLayout 通常會把這兩個元素放到LinearLayout中。FrameLayout作為改變內(nèi)容content用的。
注意:TabWidget和FrameLayout 有不同的ID命名空間android:id="@android:id/idnames",這個是必須的因此TabHost才能自動找到它,Activity需要繼承TabActivity。
Android選項(xiàng)卡Xml代碼
< ?xml version="1.0" encoding="utf-8"?>
< TabHost xmlns:android=
"http://schemas.android.com/apk/res/android"android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
< LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
< TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
< FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
< TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
< TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
< TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
< /FrameLayout>
< /LinearLayout>
< /TabHost>
< ?xml version="1.0" encoding="utf-8"?>
< TabHost xmlns:android=
"http://schemas.android.com/apk/res/android"android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
< LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
< TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
< FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
< TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
< TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
< TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
< /FrameLayout>
< /LinearLayout>
< /TabHost>
Activity需要繼承TabActivity
Android選項(xiàng)卡Java代碼
public class HelloTabWidget extends TabActivity public class HelloTabWidget extends TabActivity
Android選項(xiàng)卡Java代碼
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").
setIndicator("TAB 1").setContent(R.id.textview1));mTabHost.addTab(mTabHost.newTabSpec("tab_test2").
setIndicator("TAB 2").setContent(R.id.textview2));mTabHost.addTab(mTabHost.newTabSpec("tab_test3").
setIndicator("TAB 3").setContent(R.id.textview3));mTabHost.setCurrentTab(0);
}
上述內(nèi)容就是Android中怎么實(shí)現(xiàn)選項(xiàng)卡功能,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享文章:Android中怎么實(shí)現(xiàn)選項(xiàng)卡功能
新聞來源:http://bm7419.com/article0/jjcsio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、網(wǎng)站營銷、企業(yè)網(wǎng)站制作、用戶體驗(yàn)、商城網(wǎng)站、網(wǎng)站維護(hù)
聲明:本網(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)