TabHost实现通话记录界面

  1. //MainActivity.java
  2.  
  3. public class MainActivity extends TabActivity  
  4. {  
  5.     @Override  
  6.     public void onCreate(Bundle savedInstanceState)  
  7.     {  
  8.         super.onCreate(savedInstanceState);  
  9.         setContentView(R.layout.main);  
  10.         // 获取该Activity里面的TabHost组件  
  11.         TabHost tabHost = getTabHost();  
  12.         // 创建第一个Tab  
  13.         TabHost.TabSpec tab1 = tabHost.newTabSpec("tab1")  
  14.                 .setIndicator("已接电话"// 设置标题  
  15.                 .setContent(R.id.tab01); //设置内容  
  16.         // 添加第一个标签页  
  17.         tabHost.addTab(tab1);  
  18.         TabHost.TabSpec tab2 = tabHost.newTabSpec("tab2")  
  19.                 // 在标签标题上放置图标  
  20.                 .setIndicator("呼出电话", getResources()  
  21.                         .getDrawable(R.drawable.tiger))  
  22.                 .setContent(R.id.tab02);  
  23.         // 添加第二个标签页  
  24.         tabHost.addTab(tab2);  
  25.         TabHost.TabSpec tab3 = tabHost.newTabSpec("tab3")  
  26.                 .setIndicator("未接电话")  
  27.                 .setContent(R.id.tab03);  
  28.         // 添加第三个标签页  
  29.         tabHost.addTab(tab3);  
  30.     }  
  31. }  
  32.     
  33.  
  34. //XML文件  
  35.  
  36. <?xml version="1.0" encoding="utf-8"?>  
  37. <TabHost  
  38.    xmlns:android="http://schemas.android.com/apk/res/android"  
  39.    android:id="@android:id/tabhost"  
  40.    android:layout_width="match_parent"  
  41.    android:layout_height="match_parent"  
  42.    android:layout_weight="1">  
  43.    <LinearLayout  
  44.       android:layout_width="match_parent"  
  45.       android:layout_height="match_parent"  
  46.       android:orientation="vertical">  
  47.       <TabWidget  
  48.          android:id="@android:id/tabs"  
  49.          android:layout_width="match_parent"  
  50.          android:layout_height="wrap_content"/>  
  51.       <FrameLayout  
  52.          android:id="@android:id/tabcontent"  
  53.          android:layout_width="match_parent"  
  54.          android:layout_height="match_parent">  
  55.          <!-- 定义第一个标签页的内容 -->  
  56.          <LinearLayout  
  57.             android:id="@+id/tab01"  
  58.             android:orientation="vertical"  
  59.             android:layout_width="match_parent"  
  60.             android:layout_height="match_parent">  
  61.             <TextView  
  62.                android:layout_width="wrap_content"  
  63.                android:layout_height="wrap_content"  
  64.                android:text="女儿国国王 - 2012/12/12"  
  65.                android:textSize="11pt" />  
  66.             <TextView  
  67.                android:layout_width="wrap_content"  
  68.                android:layout_height="wrap_content"  
  69.                android:text="东海龙女 - 2012/12/18"  
  70.                android:textSize="11pt" />  
  71.          </LinearLayout>  
  72.          <!-- 定义第二个标签页的内容 -->  
  73.          <LinearLayout  
  74.             android:id="@+id/tab02"  
  75.             android:orientation="vertical"  
  76.             android:layout_width="match_parent"  
  77.             android:layout_height="match_parent">  
  78.             <TextView  
  79.                android:layout_width="wrap_content"  
  80.                android:layout_height="wrap_content"  
  81.                android:text="白骨精  - 2012/08/12"  
  82.                android:textSize="11pt" />  
  83.             <TextView  
  84.                android:layout_width="wrap_content"  
  85.                android:layout_height="wrap_content"  
  86.                android:text="蜘蛛精 - 2012/09/20"  
  87.                android:textSize="11pt" />  
  88.          </LinearLayout>  
  89.          <!-- 定义第三个标签页的内容 -->  
  90.          <LinearLayout  
  91.             android:id="@+id/tab03"  
  92.             android:orientation="vertical"  
  93.             android:layout_width="match_parent"  
  94.             android:layout_height="match_parent"  
  95.             android:textSize="11pt">  
  96.             <TextView  
  97.                android:layout_width="wrap_content"  
  98.                android:layout_height="wrap_content"  
  99.                android:text="孙悟空 - 2012/09/19"  
  100.                android:textSize="11pt" />  
  101.             <TextView  
  102.                android:layout_width="wrap_content"  
  103.                android:layout_height="wrap_content"  
  104.                android:text="猪八戒  - 2012/10/12"  
  105.                android:textSize="11pt" />  
  106.          </LinearLayout>  
  107.       </FrameLayout>  
  108.    </LinearLayout>  
  109. </TabHost>  

效果:

原文地址:https://www.cnblogs.com/wwjldm/p/6930540.html