在桌面应用中Tab控件使用得非常普遍,那么我们经常在Android中也见到以Tab进行布局的客户端。那么Android中的Tab是如何使用的呢?

1.Activity

package com.wicresoft.activity;import com.wicresoft.myandroid.R;import android.app.TabActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;@SuppressWarnings("deprecation")
public class mainActivity extends TabActivity {private TabHost tabhost;@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main_activity);//从TabActivity上面获取放置Tab的TabHosttabhost = getTabHost();tabhost.addTab(tabhost//创建新标签one.newTabSpec("one")//设置标签标题.setIndicator("红色")//设置该标签的布局内容.setContent(R.id.widget_layout_red));tabhost.addTab(tabhost.newTabSpec("two").setIndicator("黄色").setContent(R.id.widget_layout_yellow));tabhost.addTab(tabhost.newTabSpec("three").setIndicator("蓝色").setContent(R.id.widget_layout_blue));tabhost.setOnTabChangedListener(listener);}private OnTabChangeListener listener = new OnTabChangeListener(){@Overridepublic void onTabChanged(String arg0) {// TODO Auto-generated method stubLog.i("TabChange", arg0);}};
}

2.布局文件

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:id="@android:id/tabhost"><LinearLayout android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><TabWidget android:layout_width="match_parent"android:layout_height="wrap_content"android:id="@android:id/tabs"></TabWidget><FrameLayout android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:id="@android:id/tabcontent"><LinearLayout android:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/widget_layout_red"android:background="#ff0000"android:orientation="vertical"></LinearLayout><LinearLayout android:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/widget_layout_yellow"android:background="#FCD209"android:orientation="vertical"></LinearLayout><LinearLayout android:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/widget_layout_blue"android:background="#0000E3"android:orientation="vertical"></LinearLayout></FrameLayout></LinearLayout>
</TabHost>

3.Manifest文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.wicresoft.myandroid"android:versionCode="1"android:versionName="1.0" ><uses-sdkandroid:minSdkVersion="8"android:targetSdkVersion="19" /><applicationandroid:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" ><activityandroid:name="com.wicresoft.activity.mainActivity"android:label="@string/app_name"><intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter></activity></application></manifest>

4.效果

Android Tab 控件的使用相关推荐

  1. 系出名门Android(7) - 控件(View)之ZoomControls, Include, VideoView, WebView, RatingBar, Tab

    [索引页] [×××] 系出名门Android(7) - 控件(View)之ZoomControls, Include, VideoView, WebView, RatingBar, Tab, Spi ...

  2. Android开源控件ViewPager Indicator的使用方法

     1月16日厦门 OSC 源创会火热报名中,奖品多多哦   摘要 Android开源控件ViewPager Indicator的使用介绍 ViewPagerIndicator 目录[-] 1. V ...

  3. 一个Demo让你掌握Android所有控件

    一个Demo让你掌握Android所有控件 原文:一个Demo让你掌握Android所有控件 本文是转载收藏,侵删,出处:"安卓巴士"      下面给出实现各个组件的源代码: 1 ...

  4. Android开源控件收集整理

    一 .基本控件 TextView HTextView 一款支持TextView文字动画效果的Android组件库.GitHub - hanks-zyh/HTextView: Animation eff ...

  5. Android 开源控件与常用开发框架开发工具类

    Android的加载动画AVLoadingIndicatorView 项目地址: https://github.com/81813780/AVLoadingIndicatorView 首先,在 bui ...

  6. WPF下可编辑Header的Tab控件实现

    介绍 有这样一个需求,当用户双击Tab控件Header区域时, 希望可以直接编辑.对于WPF控件,提供一个ControlTemplate在加上一些Trigger就可以实现.效果如下: 代码 首先,我们 ...

  7. 日历控件的android代码,Android日历控件PickTime代码实例

    Android日历控件PickTime代码实例 发布时间:2020-10-03 16:05:51 来源:脚本之家 阅读:86 作者:手撕高达的村长 最近做项目,需要设置用户的生日,所以做这样一个功能. ...

  8. android 获取控件高度_安卓开发入门教程UI控件_ImageView

    什么是ImageView ImageView是用于显示图片的UI控件. 基础样例 1.展示本地图片 效果图 代码 <ImageViewandroid:layout_width="wra ...

  9. xamarin.android 控件,Android 库控件 - Xamarin | Microsoft Docs

    Xamarin Android 库控件Xamarin.Android Gallery control 03/15/2018 本文内容 Gallery是一种布局小组件,用于显示水平滚动列表中的项,并将当 ...

最新文章

  1. python 字符串长度变化_sizeof(string)不等于字符串长度
  2. test zero --simulator choose
  3. @pathVariable 映射URL绑定的占位符
  4. mysql scope runtime_Maven依赖scope属性详解-一个报错引发的问题 - 老郭种树
  5. 基于 DataLakeAnalytics 做跨地域的数据分析 1
  6. Oracle初学者入门指南-什么是 Metalink 或 MOS ?
  7. 【背包】小明逛超市(jzoj 2148)
  8. OpenCV学习笔记(十六):直方图均衡化:equalizeHist()
  9. 50 SD配置-定价配置-定义存取顺序
  10. linux手误rm可能不需要跑路
  11. 构建大数据平台的必要性
  12. 根据不同条件查询_好用的大数据即席查询工具——秒级响应
  13. Missing artifact com.oracle:ojdbc14:jar:10.2.0.4.0
  14. 尔雅 2017大学计算机基础答案,2018超星尔雅大学计算机基础答案.docx
  15. MINA框架客户端的使用
  16. 手机传感器你知道多少个?
  17. 吐血整理 python最全习题100道(含答案)持续更新题目,建议收藏!
  18. 【miscellaneous】视频浓缩摘要简介
  19. img标签图片404异常捕获返回默认图片
  20. 基于Java/Mysql的个人博客网站

热门文章

  1. CentOS7 常用命令大全
  2. 微信小程序video组件/腾讯视频插件,禁止拖动进度条,使用遮罩层的方式实现
  3. Android Battery(四) 电池管理
  4. 微信小程序数据拼接_最佳方式实现微信小程序分页加载数据
  5. 薪水被应届生倒挂了,很不爽,我应该跳槽吗?
  6. Delphi 中资源文件使用详解
  7. 普通用户使用su无法切到root用户的解决方法
  8. meshgrid()+plt.contourf()用法
  9. Python 使用SMTP协议发送邮件
  10. 利用phantomjs动态生成图片