1. 最简单的TabHost,Tab来自于layout下的元素 (只从1个Layout中取数据)

(1)效果图

(2)代码

1)tab_demo.xml

 

[xhtml]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>    
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"   
  3.     android:orientation="vertical"    
  4.     android:layout_width="fill_parent"    
  5.     android:layout_height="fill_parent"    
  6.     >    
  7.     <TextView android:id="@+id/tab_demo_tv1"    
  8.         android:layout_width="fill_parent"     
  9.         android:layout_height="fill_parent"     
  10.         android:text="tab_demo_tv1"    
  11.     />    
  12.     <TextView android:id="@+id/tab_demo_tv2"    
  13.         android:layout_width="fill_parent"     
  14.         android:layout_height="fill_parent"     
  15.         android:text="tab_demo_tv2"    
  16.     />    
  17.     <TextView android:id="@+id/tab_demo_tv3"    
  18.         android:layout_width="fill_parent"     
  19.         android:layout_height="fill_parent"     
  20.         android:text="tab_demo_tv3"    
  21.     />    
  22. FrameLayout>   

 

2)TabDemo.java

 

[java]  view plain copy
  1. public class TabDemo extends TabActivity {    
  2.     private TabHost tabHost;    
  3.         
  4.     public void onCreate(Bundle savedInstanceState) {    
  5.         super.onCreate(savedInstanceState);    
  6.         tabHost = getTabHost();    
  7.             
  8.         LayoutInflater.from(this).inflate(R.layout.tab_demo, tabHost.getTabContentView(), true);    
  9.         tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Tab1"null).setContent(R.id.tab_demo_tv1));   
  10.         tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Tab2"null).setContent(R.id.tab_demo_tv2));   
  11.         tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Tab3"null).setContent(R.id.tab_demo_tv3));   
  12.             
  13.         setContentView(tabHost);    
  14.     }    
  15. }     

 

更多相关文章

  1. Android(安卓)在 Fragment 中集成 React-Native(RN)步骤
  2. Android(安卓)DEX反编译后部分代码解析
  3. android ButterKnife 解决重复findViewById
  4. android解决中文乱码的所有方案
  5. 修改ExpandableListView前面展开小图标
  6. Android学习日记(1)
  7. 【Android】Android开源项目分类汇总
  8. Android测试,Android(安卓)Studio中的单元测试、UI测试和自动化测
  9. android中-----JSON例子一、 二

随机推荐

  1. ClipboardManager android剪切板使用
  2. Android之复选框对话框
  3. android 使用Okhttp封装上传JSON格式数据
  4. 2013.04.16——— android 获取状态栏高
  5. android 第一次运行应用的引导界面
  6. Eclipse 中的Android 工程突然无法启动调
  7. Android基础--电话拨号器
  8. Ubuntu 12.04 安装 Tomcat8 遇到的问题
  9. Android第二十九期 - 各种Android的App框
  10. gdbserver/remote debug on android