TabHost简介

虽然,官方建议用Fagment取代TabHost,但是我们还是大概的介绍一下。TabHost是一种非常简单的组件,TabHost可以很方便的在窗口放置多个标签页,每一个标签页相当于获得了一个摆放位置。

注意

TabHost的内部需要两个组件一个是TabWidget和FrameLayout两个组件。

通话记录界面

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
android:layout_height="match_parent"
    android:layout_weight="1"
    android:id="@android:id/tabhost"
    >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TabWidget
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@android:id/tabs"/>
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@android:id/tabcontent">
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:id="@+id/tab01">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"/>

                </LinearLayout>
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:id="@+id/tab02">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"/>

            </LinearLayout>
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:id="@+id/tab03">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"/>

            </LinearLayout>
            </FrameLayout>
        </LinearLayout>

</TabHost>
package peng.liu.test;

import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;

public class MainActivity extends TabActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TabHost tabHost = getTabHost();
        TabHost.TabSpec tabSpec = tabHost.newTabSpec("tab01").setIndicator("已接电话").setContent(R.id.tab01);
        tabHost.addTab(tabSpec);
        TabHost.TabSpec tabSpec1 = tabHost.newTabSpec("tab02").setIndicator("呼叫电话").setContent(R.id.tab02);
        TabHost.TabSpec tabSpec2 = tabHost.newTabSpec("tab03").setIndicator("未接电话").setContent(R.id.tab03);
        tabHost.addTab(tabSpec1);
        tabHost.addTab(tabSpec2);
    }
}

效果图

Android的TabHost组件-android的学习之旅(四十)的更多相关文章

  1. 12.Android之Tabhost组件学习

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

  2. Android四大组件之一Service介绍-android学习之旅(十二)

    基本概念: service是android四大组件之一,运行在后台执行耗时操作,并不提供用户界面.其他组件如acticity可以通过startService启动该组件,也可以通过bindService ...

  3. Android学习笔记(四十):Preference的使用

    Preference直译为偏好,博友建议翻译为首选项.一些配置数据,一些我们上次点击选择的内容,我们希望在下次应用调起的时候依旧有效,无须用户再一次进行配置或选择.Android提供preferenc ...

  4. Android学习笔记(四十):Preference使用

    Preference从字面上看偏好,译为首选项. 一些配置数据,一些我们上次点击选择的内容.我们希望在下次应用调起的时候依旧有效,无须用户再一次进行配置或选择.Android提供preference这 ...

  5. android布局Relative和gridLayout-android学习之旅(十六)

    Relative布局简介 相对布局的组件是由兄弟组件和父组价决定的,因此这种布局被称为相对布局. 属性设置介绍 RelativeLayout.Layoutparam中只能设置为true和false的属 ...

  6. android布局##TableLayout和FrameLayout-android学习之旅(十五)

    TableLayout 表格布局 tablelayout简介 表格布局有TableLayout代表,但是它的本质定义仍然是线性管理器.表格布局采用行和列来管理UI,但是不需要明确的定义多少行,多少列, ...

  7. Android的ViewAnimator及其子类ViewSwitcher-android学习之旅(三十三)

    ViewAnimator继承了FrameLayout,多个组件重合在一起,可以加入多个组件,然后切换的时候会有动画. ViewAnimator及其子类的继承关系 ViewAnimator常用属性 Vi ...

  8. 开发了5年android,我开始了go学习之旅

    前言 做了近5年的android开发,最近项目也是不怎么忙,空闲的时候总会思考一些事情,不过作为移动开发,我个人觉得很有必要学习后台开发,由于公司是Go语言开发的,了解go语言一段时间后,我发现go语 ...

  9. android:id="@android:id/tabhost" 、android:id="@+id/llRoot" 、android:id="@id/llRoot" 之间的区别

    由于快要放暑假了,所以最近这俩周把Android方面的知识复习一下,准备找个实习工作. 顺便把自己的总结更大家分享一下,共同进步,谢谢.... 一. android:id="@android ...

随机推荐

  1. xx学院学员评优评奖管理系统

    [勤拂拭软件,软件开发,毕业设计,程序作业,论文写作指导:q-[1215714557]  加好友请注明:勤拂拭)] 之前帮助一个军校学生做的一个评优评奖管理系统,该系统主要用于学校学生评优评先使用. ...

  2. SpringCloud学习之Ribbon

    一.负载均衡与Ribbon 负载均衡,在集群中是很常见的一个“名词”,顾名思义是根据一定的算法将请求分摊至对应的服务节点上,常见的算法有如下几种: 轮询法:所有请求被依次分发到每台应用服务器上,每台服 ...

  3. mongodb数据库备份迁移 windows -> linux

    mongodb数据库备份迁移 windows -> linux cd 到本机mongodb的安装目录 如: C:\Program Files\MongoDB\Server\3.4\bin 可以发 ...

  4. 使用 OpenCV 与 Face++ 人脸识别

    今天看到一篇文章<使用 OpenCV 与 Face++ 实现人脸解锁>,感觉挺好玩,就照着作者的讲解,写了一下.详细内容还请看原作者文章. # *^_^* coding:utf-8 *^_ ...

  5. RHEL Linux常用指令

    查询已安装软件包 rpm -qa|grep * 安装软件 rpm -ivh * 查询Linux版本 uname -a lsb_release -a cat /etc/redhat-release ca ...

  6. Java 读取Excel文件

    https://www.cnblogs.com/wwzyy/p/5962076.html   先把上面的参考博客看了,如果会导入包的话,下面的教程就直接忽略emm     这时候,你应该把jar包下载 ...

  7. C语言完美体系

    **第 1 篇 C 语言第一阶段 13 1.1C 语言第一阶段--语言课程概述 13 1.1.1 什么是语言,什么是 C 语言 13 1.1.2 基本常识 14 1.1.3 人与计算机之间的更好的交互 ...

  8. android 小项目------黑名单app

    周一的时候,同事在群里问到了黑名单功能,他说网上都没有找到一个完整的,记得谁说过一句,当都没有做过的时候,这就是机会.这几天公司事比较多,只能晚上抽时间写写,直到今天才完整的做出来. 具体效果的话大家 ...

  9. mysql 常见语句

    事务 默认是开启了autocommit,可以通过show variables like 'autocommit';查看. 如果临时需要取消autocommit,可以通过START TRANSACTIO ...

  10. iOS开源加密相册Agony的实现(四)

    简介 虽然目前市面上有一些不错的加密相册App,但不是内置广告,就是对上传的张数有所限制.本文介绍了一个加密相册的制作过程,该加密相册将包括多密码(输入不同的密码即可访问不同的空间,可掩人耳目).Wi ...