真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Tabhost以及其用法

TabHost是一種非常使用的組件,TabHost可以方便的在窗口上放置多個(gè)標(biāo)簽頁,每個(gè)標(biāo)簽頁相當(dāng)于或得了一個(gè)與外部容器相同大小的組件擺放區(qū)域。

成都創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的柞水網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

與TabHost 結(jié)合使用的組件

  TabWidget:代表選項(xiàng)卡的標(biāo)簽條。

   TabSpec:代表選項(xiàng)卡的一個(gè)Tab頁面。

創(chuàng)建添加選項(xiàng)卡的方法:

 newTabSpec():創(chuàng)建選項(xiàng)卡

 addTab():添加選項(xiàng)卡

使用TabHost的步驟:

  1. 在界面布局中定義TabHost組件

  2. Activity繼承TabActivity

  3. 調(diào)用TabActivity的getTabHost()方法獲取TabHost

  4. 通過TabHost對象的方法來創(chuàng)建添加選項(xiàng)卡。

  5. xml version="1.0" encoding="utf-8"?>
  6. <LinearLayout
  7.     xmlns:android="http://schemas.android.com/apk/res/android"
  8.     android:layout_width="match_parent" android:layout_height="match_parent"
  9.    android:orientation="vertical"
  10.     >
  11.    
  12. <TabHost
  13.     android:layout_width="match_parent" android:layout_height="match_parent"
  14.     android:id="@android:id/tabhost"
  15.     android:layout_weight="1"
  16.     >
  17.     <LinearLayout
  18.         android:layout_width="match_parent"
  19.         android:layout_height="match_parent"
  20.         android:orientation="vertical"
  21.         >
  22.         <TabWidget
  23.             android:id="@android:id/tabs"
  24.             android:layout_width="match_parent"
  25.             android:layout_height="wrap_content">TabWidget>//代表選項(xiàng)卡的標(biāo)簽條。
  26.         <FrameLayout
  27.             android:id="@android:id/tabcontent"
  28.             android:layout_width="match_parent"
  29.             android:layout_height="match_parent">
  30.             
  31.             <LinearLayout
  32.                 android:id="@+id/tab01"
  33.                 android:orientation="vertical"
  34.                 android:layout_width="fill_parent"
  35.                 android:layout_height="fill_parent">
  36.                 <TextView
  37.                     android:layout_width="fill_parent"
  38.                     android:layout_height="fill_parent"
  39.                     android:text="消息"
  40.                     android:textSize="30sp"
  41.                     />
  42.             LinearLayout>
  43.             <LinearLayout
  44.                 android:id="@+id/tab02"
  45.                 android:orientation="vertical"
  46.                 android:layout_width="fill_parent"
  47.                 android:layout_height="fill_parent">
  48.                 <TextView
  49.                     android:layout_width="fill_parent"
  50.                     android:layout_height="fill_parent"
  51.                     android:text="賽事"
  52.                     android:textSize="30sp"
  53.                     />
  54.             LinearLayout>
  55.             <LinearLayout
  56.                 android:id="@+id/tab03"
  57.                 android:orientation="vertical"
  58.                 android:layout_width="fill_parent"
  59.                 android:layout_height="fill_parent">
  60.                 <TextView
  61.                     android:layout_width="fill_parent"
  62.                     android:layout_height="fill_parent"
  63.                     android:text="我的頁面"
  64.                     android:textSize="30sp"
  65.                     />
  66.             LinearLayout>
  67.         FrameLayout>
  68.  
  69.     LinearLayout>
  70. TabHost>
  71. LinearLayout>
  72. 注意:必須使用這樣的,其他的id是錯(cuò)誤的
  73. android:id="@android:id/tabhost"
  74.  android:id="@android:id/tabs"
  75.  android:id="@android:id/tabcontent"
  76.  引用android系統(tǒng)已有的id
  77. public class MainActivity extends TabActivity{ //Activity繼承TabActivity
  78.  
  79.     @Override
  80.     protected void onCreate(Bundle savedInstanceState) {
  81.         super.onCreate(savedInstanceState);
  82.         setContentView(R.layout.main_activity);
  83.          //調(diào)用TabActivity的getTabHost()方法獲取TabHost
  84.         TabHost tabHost=getTabHost();
  85.         //創(chuàng)建第一個(gè)Tab頁
  86.         TabHost.TabSpec tab1=tabHost.newTabSpec("tab1")
         
  87.                 .setIndicator("賽事")//設(shè)置標(biāo)題
  88.                 .setContent(R.id.tab01);
  89.         //添加第一個(gè)tab頁
  90.         tabHost.addTab(tab1);
  91.         TabHost.TabSpec tab2=tabHost.newTabSpec("tab2")
  92.                 .setIndicator("消息")//設(shè)置標(biāo)題
  93.                 .setContent(R.id.tab02);
  94.         //添加第一個(gè)tab頁
  95.         tabHost.addTab(tab2);
  96.  
  97.         TabHost.TabSpec tab3=tabHost.newTabSpec("tab3")
  98.                 .setIndicator("我")//設(shè)置標(biāo)題
  99.                 .setContent(R.id.tab03);
  100.         //添加第一個(gè)tab頁
  101.         tabHost.addTab(tab3);
  102.     }
  103. }


文章標(biāo)題:Tabhost以及其用法
本文鏈接:http://weahome.cn/article/jpichh.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部