Android Tab 控件详解及实例

在桌面应用中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;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
//从TabActivity上面获取放置Tab的TabHost
tabhost = 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(){
@Override
public void onTabChanged(String arg0) {
// TODO Auto-generated method stub
Log.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-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android: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
# 控件
# Tab详解及实例
# Android MarginDesign控件TabLayout导航栏使用详解
# Android Navigation TabBar控件实现多彩标签栏
# 详解Android中ViewPager的PagerTabStrip子控件的用法
# Android控件之TabHost用法实例分析
# android TabHost(选项卡)的使用方法
# android 选项卡(TabHost)如何放置在屏幕的底部
# Android TabLayout(选项卡布局)简单用法实例分析
# Android仿微信底部实现Tab选项卡切换效果
# Android多个TAB选项卡切换效果
# Android实现网易Tab分类排序控件实现
# 希望能
# 中也
# 谢谢大家
# 如何使用
# 客户端
# main_activity
# layout
# setContentView
# getTabHost
# addTab
# newTabSpec
# setIndicator
# protected
# Override
# tabhost
# void
# super
# savedInstanceState
# onCreate
# setContent
相关文章:
标准网站视频模板制作软件,现在有哪个网站的视频编辑素材最齐全的,背景音乐、音效等?
头像制作网站在线制作软件,dw网页背景图像怎么设置?
,制作一个手机app网站要多少钱?
在线制作视频网站免费,都有哪些好的动漫网站?
香港服务器租用费用高吗?如何避免常见误区?
湖南网站制作公司,湖南上善若水科技有限公司做什么的?
岳西云建站教程与模板下载_一站式快速建站系统操作指南
如何批量查询域名的建站时间记录?
建站之家VIP精选网站模板与SEO优化教程整合指南
详解ASP.NET 生成二维码实例(采用ThoughtWorks.QRCode和QrCode.Net两种方式)
临沂网站制作企业,临沂第三中学官方网站?
制作营销网站公司,淘特是干什么用的?
黑客如何通过漏洞一步步攻陷网站服务器?
常州自助建站工具推荐:低成本搭建与模板选择技巧
建站主机如何选?高性价比方案全解析
商务网站制作工程师,从哪几个方面把握电子商务网站主页和页面的特色设计?
活动邀请函制作网站有哪些,活动邀请函文案?
如何快速完成中国万网建站详细流程?
寿县云建站:智能SEO优化与多行业模板快速上线指南
,柠檬视频怎样兑换vip?
如何通过wdcp面板快速创建网站?
宝塔面板创建网站无法访问?如何快速排查修复?
如何做网站制作流程,*游戏网站怎么搭建?
视频网站制作教程,怎么样制作优酷网的小视频?
如何用花生壳三步快速搭建专属网站?
香港服务器部署网站为何提示未备案?
php能控制zigbee模块吗_php通过串口与cc2530 zigbee通信【介绍】
建站主机选购指南:核心配置与性价比推荐解析
专业制作网站的公司哪家好,建立一个公司网站的费用.有哪些部分,分别要多少钱?
香港代理服务器配置指南:高匿IP选择、跨境加速与SEO优化技巧
西安专业网站制作公司有哪些,陕西省建行官方网站?
php8.4新语法match怎么用_php8.4match表达式替代switch【方法】
如何在阿里云部署织梦网站?
陕西网站制作公司有哪些,陕西凌云电器有限公司官网?
如何通过西部数码建站助手快速创建专业网站?
定制建站策划方案_专业建站与网站建设方案一站式指南
C++中引用和指针有什么区别?(代码说明)
如何获取上海专业网站定制建站电话?
道歉网站制作流程,世纪佳缘致歉小吴事件,相亲网站身份信息伪造该如何稽查?
儿童网站界面设计图片,中国少年儿童教育网站-怎么去注册?
矢量图网站制作软件,用千图网的一张矢量图做公司app首页,该网站并未说明版权等问题,这样做算不算侵权?应该如何解决?
保定网站制作方案定制,保定招聘的渠道有哪些?找工作的人一般都去哪里看招聘信息?
如何制作一个表白网站视频,关于勇敢表白的小标题?
制作网站软件推荐手机版,如何制作属于自己的手机网站app应用?
如何在企业微信快速生成手机电脑官网?
如何在Windows 2008云服务器安全搭建网站?
魔方云NAT建站如何实现端口转发?
建站之星如何修改网站生成路径?
如何设置并定期更换建站之星安全管理员密码?
如何在云虚拟主机上快速搭建个人网站?
*请认真填写需求信息,我们会在24小时内与您取得联系。