我们在开发Android程序的时候,会经常使用Tab界面,但有些时候我们需要动态创建Tab页,这里就简单介绍创建Tab的方法。

第一步 界面格局设定

<?xml version="1.0" encoding="utf-8"?><TabHostandroid:layout_width="fill_parent"android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"android:id="@android:id/tabhost"><TabWidgetandroid:id="@android:id/tabs"android:layout_width="wrap_content"android:layout_height="wrap_content"></TabWidget><FrameLayoutandroid:id="@android:id/tabcontent"android:layout_width="wrap_content"android:layout_height="wrap_content"android:paddingTop="65px"><LinearLayoutandroid:id="@+id/content1"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:text="tab1"android:id="@+id/phone"android:layout_width="fill_parent"android:layout_height="wrap_content"></TextView></LinearLayout><LinearLayoutandroid:id="@+id/content2"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:text="tab2"android:id="@+id/mail"android:layout_width="fill_parent"android:layout_height="wrap_content"></TextView></LinearLayout></FrameLayout></TabHost>
第二步 编写TabActivity的代码
package eoe.stu.ui.tabactivity;import android.app.TabActivity;import android.os.Bundle;import android.widget.TabHost;import android.widget.TabHost.TabSpec;public class AndroidEggTabActivity extends TabActivity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);TabHost tabs = getTabHost();TabSpec tab1 = tabs.newTabSpec("tab1");tab1.setIndicator("Android");tab1.setContent(R.id.content1);tabs.addTab(tab1);TabSpec tab2 = tabs.newTabSpec("tab2");tab2.setIndicator("Egg");tab2.setContent(R.id.content2);tabs.addTab(tab2);tabs.setCurrentTab(0);}}



转载:http://www.adobex.com/android/source/details/00000427.htm

更多相关文章

  1. 没有一行代码,「2020 新冠肺炎记忆」这个项目却登上了 GitHub 中
  2. 【Android(安卓)开发教程】GridView
  3. Android(安卓)-- 官方下拉刷新SwipeRefreshLayout
  4. android之开机跳过锁屏界面自启动应用
  5. Android:实现装备购买
  6. Android与JS通过JSBridge(BridgeWebView )相互调用详解
  7. Eclipse Android(安卓)代码自动提示功能
  8. Android(安卓)仿RxDialog自定义DialogFragment
  9. android 多媒体相关代码概况—(JAVA SCOPE)

随机推荐

  1. Kotlin for Android使用教程(一)
  2. 电话录音录制双方的声音
  3. 关于Spring for Android
  4. Android跳转到应用商店及常见APP对应包名
  5. ubuntu下搭建ecshop
  6. Android(安卓)读取资源文件下面的文件
  7. Android(安卓)网络提交数据(使用Asynchron
  8. android 系统相应的服务
  9. Android(安卓)接口和抽象类的区别
  10. android中AlertDialog设置圆角