1.布局XML:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabhost">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/bottomtip"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="@string/funPageBtn2"
android:gravity="center_horizontal|center_vertical"
android:layout_alignParentTop="true"
android:textColor="@android:color/white"
android:background="@android:color/black"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@android:id/tabs"
android:layout_below="@+id/bottomtip"
/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@android:color/black"
/>
</RelativeLayout> </TabHost>

布局效果理解:

2.Activity类实现

package com.test.appdemo1.actlearn;

import com.test.appdemo1.R;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec; @SuppressWarnings("deprecation")
public class TabOptTopAct extends TabActivity { private TabHost tabHost;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabtoplayout);
initTab();
} private void initTab() {
tabHost = getTabHost();
TabSpec tabSpec = null;
Intent intent = new Intent(this,MainActivity.class);
//第一个
tabSpec = tabHost.newTabSpec("tab1")
.setIndicator("首页",getResources().getDrawable(R.drawable.home))
.setContent(intent);
tabHost.addTab(tabSpec); //第二个
intent = new Intent(this,NextActivity.class);
tabSpec = tabHost.newTabSpec("tab2")
.setIndicator("邮件",getResources().getDrawable(R.drawable.mail))
.setContent(intent);
tabHost.addTab(tabSpec); //第三个
intent = new Intent(this,ServiceActDemo.class);
tabSpec = tabHost.newTabSpec("tab3")
.setIndicator("音乐",getResources().getDrawable(R.drawable.music))
.setContent(intent);
tabHost.addTab(tabSpec); //第四个
intent = new Intent(this,FrameLearnLayoutAct.class);
tabSpec = tabHost.newTabSpec("tab4")
.setIndicator("计算",getResources().getDrawable(R.drawable.calc))
.setContent(intent);
tabHost.addTab(tabSpec); tabHost.setCurrentTab(1);
} public void onBackPressed() {
super.onBackPressed();
finish();
}
}

最后说明:如果想把选项卡放到顶部只需修改布局文件中RelativeLayout里面的三个元素的位置

若有问题请大家指正.

程序运行效果如上图片所示.

Android选项卡TabHost方式实现的更多相关文章

  1. android 选项卡TabHost

    选项卡主要有TabHost.TabWiget和 FramentLayout3个组件组成,用于实现一个多标签的用户界面,通过他可以将一个复杂的对话分隔成若干个标签页,实现对信息的分类显示和管理.使用给组 ...

  2. Android选项卡TabHost功能和用法

    1.布局文件 <TabHost xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  3. Android 自学之选项卡TabHost

    选项卡(TabHost)是一种非常实用的组件,TabHost可以很方便地在窗口上放置多个标签页,每个标签页相当于获得了一个与外部容器相同大小的组建摆放区域.通过这种方式,就可以在一个容器中放置更多组件 ...

  4. Android零基础入门第63节:过时但仍值得学习的选项卡TabHost

    原文:Android零基础入门第63节:过时但仍值得学习的选项卡TabHost 由于前几天参加一个学习培训活动,几乎每天都要从早晨7点到晚上一两点,没有什么时间来分享,实在抱歉中间断更了几天.从今天开 ...

  5. android学习--TabHost选项卡组件

    TabHost是一种非常有用的组件,TabHost能够非常方便地在窗体上放置多个标签页,每一个标签页获得了一个与外部容器同样大小的组件摆放区域.在手机系统的应用类似"未接电话".& ...

  6. Android 通过findViewById方式创建TabHost

    package org.shuxiang.tabhostsample; import android.os.Bundle; import android.app.ActivityGroup; impo ...

  7. 12.Android之Tabhost组件学习

    TabHost是整个Tab的容器,TabHost的实现有两种方式: 第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.各个Tab中的内容在布 ...

  8. Android:TabHost实现Tab切换

    TabHost是整个Tab的容器,包含TabWidget和FrameLayout两个部分,TabWidget是每个Tab的表情,FrameLayout是Tab内容. 实现方式有两种: 1.继承TabA ...

  9. Android学习Tabhost、gallery、listview、imageswitcher

    Tabhost控件又称分页控件,在很多的开发语言中都存在.它可以拥有多个标签页,每个标签页可以拥有不同的内容.android中,一个标签页可以放 一个view或者一个activity.TabHost是 ...

随机推荐

  1. js解决checkbox全选和反选的问题

    function SelectAll() { var checkboxs=document.getElementsByName("chk_list"); for (var i=0; ...

  2. [转载]jquery获取元素索引值index()方法:

    jquery的index()方法 搜索匹配的元素,并返回相应元素的索引值,从0开始计数. 如果不给 .index() 方法传递参数,那么返回值就是这个jQuery对象集合中第一个元素相对于其同辈元素的 ...

  3. setjump 和 longjump

    goto语句可以用于同一个函数内异常处理,不幸的是,goto是本地的,它只能跳到所在函数内部的标号上.为了解决这个限制,C函数库提供了setjmp()和longjmp()函数,它们分别承担非局部标号和 ...

  4. ArcGIS学习记录-Excel和Txt中XY点数据生成点Shape文件方法

    (一)Excel中XY点数据生成点Shape文件方法 1.Excel表如下:   2.点击ArcGIS中的"+"号按钮,添加数据.选择第一步中制作好的Excel文件,点击Add按钮 ...

  5. WordPress添加网站图标

    如何给WordPress添加网站图标_百度经验 http://jingyan.baidu.com/article/54b6b9c0d549622d583b4788.html   看到很多网站都带有ic ...

  6. python脚本工具 - 4 获取系统当前时间

    #! /usr/bin/python import time current_time = time.strftime("%Y-%m-%d %H:%M") print curren ...

  7. WCF实例上下文

    实例上下文模式(IntanceContext Mode)表示服务端的服务实例与客户端的服务代理的绑定方式. 在WCF中有三种不同的实例上下文模式,单调(Per-Call)模式,会话(Per-Sessi ...

  8. 到底怎么样才叫看书?——Tony Zhao's

    到底怎么样才叫看书?——上篇 目录: 一.引入 二.经历了就能理解 三.读书要分级 四.只读经典 五.别吝惜你动笔的那点时间 一.引入 看到这个题目的时候你可能会感到有点好笑:“这还用问,看书就是把书 ...

  9. 制作计算器的代码(C#)

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. poj 2299 Ultra-QuickSort (归并排序 求逆序数)

    题目:http://poj.org/problem?id=2299 这个题目实际就是求逆序数,注意 long long 上白书上的模板 #include <iostream> #inclu ...