Android基础:十八般武器之TabHost
来源:互联网 发布:软考程序员教程 编辑:程序博客网 时间:2024/06/06 10:52
main.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" ><FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"/><TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0"/></LinearLayout></TabHost>
tab1.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这里是tab1" /></LinearLayout>
tab2.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这里是tab2" /></LinearLayout>
TabHostActivity.java
package com.edu.tabhost;import android.app.TabActivity;import android.content.Intent;import android.os.Bundle;import android.widget.TabHost;public class TabHostActivity extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tabInit(); } public void tabInit(){ TabHost th = this.getTabHost();//实例化TabHost //第一个标签 Intent i1 = new Intent(); i1.setClass(this, tab1activity.class); TabHost.TabSpec ts1 = th.newTabSpec("tab1");//创建标签项 ts1.setIndicator("标签1");//设置指示器文本 ts1.setContent(i1);//填充布局 th.addTab(ts1);//填加到TabHost //第二个标签 Intent i2 = new Intent(); i2.setClass(this, tab2activity.class); TabHost.TabSpec ts2 = th.newTabSpec("tab2");//创建标签项 ts2.setIndicator("标签2");//设置指示器文本 ts2.setContent(i2);//填充布局 th.addTab(ts2);//填加到TabHost //默认标签 th.setCurrentTab(0); }}
tab1activity.java
package com.edu.tabhost;import android.app.Activity;import android.os.Bundle;public class tab1activity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsetContentView(R.layout.tab1);super.onCreate(savedInstanceState);}}tab2activity.java
package com.edu.tabhost;import android.app.Activity;import android.os.Bundle;public class tab2activity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsetContentView(R.layout.tab2);super.onCreate(savedInstanceState);}}
0 0
- Android基础:十八般武器之TabHost
- Android基础:十八般武器之Button
- Android基础:十八般武器之TextView
- Android基础之TabHost
- Android绘图Canvas十八般武器之Shader详解及实战篇(上)
- Android绘图Canvas十八般武器之Shader详解及实战篇(下)
- Android绘图Canvas十八般武器之Shader详解及实战篇(上)
- 绘图Canvas十八般武器之Shader详解及实战
- 自动化测试开发人员的十八般武器
- Android基础-TabHost控件
- android TabHost基础讲解
- 网络安全基础之<十八>
- Android开发之TabHost
- Android之TabHost
- android之TabHost
- android 之 TabHost
- android控件之TabHost
- Android之TabHost布局
- Could not load the "logo.png" image referenced from a nib in the bundle with identifier
- 虚拟摄像头驱动程序框架分析
- VC++工程中使用C文件
- 谈谈Objective-C的警告
- 用 Python 解回文数的个数
- Android基础:十八般武器之TabHost
- clojure中检查依赖的包是否有更新
- 第十二周项目一n的阶乘
- 第十二周项目 4 银行系统(搭一个框架)
- Js获取当前页面URL的一些属性
- 第十二周项目三(4):第20个fibnacci数
- linux下解压命令大全
- Unity3D-脚本编绎
- tq2440移植java虚拟机