1、布局文件

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.helloword.TabActivity" > <LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/> <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout> </LinearLayout> </TabHost>

tab1.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="左边 tab"/> </LinearLayout>

tab2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="right tab"/> </LinearLayout>

2、Activity

package com.example.helloword;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost; public class TabActivity extends Activity implements View.OnClickListener{ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab); TabHost tabHost = findViewById(android.R.id.tabhost);
tabHost.setup(); LayoutInflater inflater = LayoutInflater.from(this); inflater.inflate(R.layout.tab1, tabHost.getTabContentView());
inflater.inflate(R.layout.tab2, tabHost.getTabContentView()); tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("left").setContent(R.id.tab1)); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("right").setContent(R.id.tab2)); } @Override
public void onPointerCaptureChanged(boolean hasCapture) {
// TODO Auto-generated method stub } @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub } }

Android选项卡TabHost功能和用法的更多相关文章

  1. Android选项卡TabHost方式实现

    1.布局XML: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android= ...

  2. android 选项卡TabHost

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

  3. Android ViewSwitcher 的功能与用法

    ViewSwitcher 代表了视图切换组件, 本身继承了FrameLayout ,可以将多个View叠在一起 ,每次只显示一个组件.当程序控制从一个View切换到另个View时,ViewSwitch ...

  4. 选项卡(TabHost)的功能与用法

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

  5. Android 自学之画廊视图(Gallery)功能和用法

    Gallery与之前讲的Spinner有共同的父类:AbsSpinner,表明Gallery和Spinner都是一个列表框.他们之间的区别在于Spinner显示的是一个垂直的列表框,而Gallery显 ...

  6. Android 自学之选项卡TabHost

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

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

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

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

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

  9. 浅谈Android选项卡(三)

    上一节介绍了TabActivity的简单用法,但是现在的Api中已经不建议使用了,建议使用Fragment来替代以上的功能,下面介绍下使用Fragment和ViewPager的结合使用. http:/ ...

随机推荐

  1. Oracle系列十五 控制用户权限

    权限 数据库安全性 --系统安全性 --数据安全性 系统权限: 对于数据库的权限 对象权限: 操作数据库对象的权限 系统权限 超过一百多种有效的权限 数据库管理员具有高级权限以完成管理任务,例如: 创 ...

  2. windows下安装zk

    1 下载安装包并解压 2 修改conf下配置文件名字 zoo_sample.cfg 文件名改为 zoo.cfg 3 启动zk zKServer.cmd 4启动客户端连接测试 zKCli.cmd 127 ...

  3. powershell 开windows 端口

    @echo off @echo 请以管理员身份运行 set /p portRemark=请输入端口备注: set /p port=请输入端口号: powershell -command "N ...

  4. (原)x264代码中的码流控制学习

    (本文主要是自己的学习笔记,如果有误,请留言,一起讨论和更正.)这里采用x264的代码进行走读的方式,来学习qp在码流控制中过程. 在ABR模式下,当我们设置一个bitrate的平均码率以后,x264 ...

  5. iOS开发 判定某个时间是否属于这个时间段

    - (BOOL)isBetweenDate { //设置的是中国时间 NSString *startTime=@"13:01"; NSString *expireTime=@&qu ...

  6. (转)搭建Elasticsearch和kibana环境

    搭建Elasticsearch和kibana环境 作者:IT云清 原文:https://blog.csdn.net/weixin_39800144/article/details/81162002 1 ...

  7. linux 下mysql 关闭 启动

    一. 启动 .使用 service 启动:service mysql start .使用 mysqld 脚本启动:/etc/init.d/mysql start .使用 safe_mysqld 启动: ...

  8. Spring-boot2X基于sharding-jdbc3.x分表分库

    ShardingSphere是一套开源的分布式数据库中间件解决方案组成的生态圈,它由Sharding-JDBC.Sharding-Proxy和Sharding-Sidecar(计划中)这3款相互独立的 ...

  9. javascript 从对象数组中 按字段/属性取最大值或最小值

    var array=[ { "index_id": 119, "area_id": "18335623", "name" ...

  10. K8S+GitLab+.net core-自动化分布式部署-3

    K8S+GitLab-自动化分布式部署ASP.NET Core(三) 更新镜像版本并部署到K8S上   一.介绍 前一篇,介绍了ASP.NET Core部署到K8S上,下面介绍我们在发布新一版本中怎么 ...