Android -- TabHost
TabHost 也就相当于Windows下的选项框
有两种实现方式
1. 继承TabActivity (已经废弃):从TabActivity中用getTabHost()方法获取TabHost
2. 在布局文件中定义TabHost,但是TabWidget的id必须是@android:id/tabs,FrameLayout的id必须是@android:id/tabcontent.
主要介绍第二种方法的使用
Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/hometabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <!-- 此Id不可改变 -->
<TabHost
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</TabWidget> <!-- 此Id不可改变 -->
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" > <TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="第一个选项框" /> <TextView
android:id="@+id/photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="第二个选项框" /> <TextView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="第三个选项框" />
</FrameLayout>
</LinearLayout>
</TabHost> </LinearLayout>
MainActivity
@ Override
protected void onCreate ( Bundle savedInstanceState ) { super.onCreate ( savedInstanceState );
setContentView ( R.layout.activity_main ); TabHost tabHost = ( TabHost ) findViewById ( R.id.tabhost );
/**
* 如何继承TabActivity 则不需要回调该函数
*/
tabHost.setup ( ); /**
* 增加标题头文件 ,相当于选项框
*/
tabHost.addTab ( tabHost.newTabSpec ( "tab1" )
.setIndicator ( "文本新闻" ,
getResources ( ).getDrawable (
R.drawable.ic_launcher ) )
.setContent ( R.id.text ) );
//添加选项框二
tabHost.addTab ( tabHost.newTabSpec ( "tab2" )
.setIndicator ( "图片新闻" ,
getResources ( ).getDrawable (
R.drawable.ic_launcher ) )
.setContent ( R.id.photo ) );
//添加选项框三
tabHost.addTab ( tabHost.newTabSpec ( "tab3" )
.setIndicator ( "视频新闻" ,
getResources ( ).getDrawable (
R.drawable.ic_launcher ) )
.setContent ( R.id.video ) ); }
Android -- TabHost的更多相关文章
- Android tabhost下的activity怎样获取传来的值
android tabhost下的activity怎样获取传来的值,具体解决方案如下: 解决方案: 其他activity设置intent:Intent intent=new Intent(); int ...
- Android - TabHost 与 Fragment 制作页面切换效果
Android - TabHost 与 Fragment 制作页面切换效果 Android API 19 , API 23 三个标签页置于顶端 效果图: 在文件BoardTabHost.java中定义 ...
- Android——TabHost(标签容器)相关知识总结贴
android 2.3 r1 中文 api (58) —— TabHost http://www.apkbus.com/android-18911-1-1.html android中文api (5 ...
- Android TabHost使用
TabHost是Android中自带的选项卡控件,效果图如下: 主布局文件 <RelativeLayout xmlns:android="http://schemas.android. ...
- Android -- TabHost、Fragment、状态保存、通信
工程结构 TabAFm到Ta ...
- Android TabHost中Activity之间传递数据
例子1: TabHost tabhost = (TabHost) findViewById(android.R.id.tabhost); tabhost.setup(this.getLocalActi ...
- Android TabHost 动态修改图标或者动态改变标题
那时客户需要实现在TabHost标题上动态显示从数据库获取的个数.起初这样思考的,从数据库 获取个数是非常简单,但是要把获取的个数显示在TabHost标题,思前想后,想用Handler来异步实现消息传 ...
- Android TabHost中实现标签的滚动以及一些TabHost开发的奇怪问题
最近在使用TabHost的时候遇到了一些奇怪的问题,在这里总结分享备忘一下. 首先说一点TabActivity将会被FragmentActivity所替代,但是本文中却是使用的TabActivity. ...
- Android TabHost TabWidget 去除黑线(底部下划线)
采用TabHost布局时,往往会发现默认的系统风格与软件风格很不协调,比如TabWidget的下划线影响布局效果.通常情况下会去除其下划线.如果是采用xml布局文件,在TabWidget的属性项设置a ...
随机推荐
- Delphi字符串的基本操作与常用函数
参考:http://www.cnblogs.com/pchmonster/archive/2011/12/16/2290034.html 结合这个博客一起学习:http://www.cnblogs.c ...
- Linux Shell 高级编程技巧2----shell工具
2.shell工具 2.1.日志文件 简介 创建日志文件是很重要的,记录了重要的信息.一旦出现错误,这些信息对于我们排错是非常有用的:监控的信息也可以记录到日 ...
- n的阶乘高精度算法【阶乘】
C语言实验——求阶乘(循环结构) Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 题目链接:http://acm.sdut.edu ...
- Babelfish(二分查找,字符串的处理略有难度,用sscanf输入)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 28581 Accepted: 12326 题目链接: ...
- 【20140113-2】MyEclipse生成javadoc时出错:编码GBK的不可映射字符
今天生成java doc文档时,出现了如下所示的错误: 正在装入软件包 com.wisdom.test 的源文件...F:\workspace\StringUtils\src\com\wisdom\t ...
- [LeetCode] Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tr ...
- Web分布式架构演变过程
1 单台服务器 2 应用服务器与数据库服务器 文件服务器分开 3 数据库 缓存 读写分离 实时写 非实时写 4 应用服务器集群 需要再配一台”负载均衡调度器“,nginx 5 数据库拆封 主库 ...
- PRD产品需求文档
什么是PRD? PRD是Product Requirement Document的英文缩写,即产品需求文档的意思.PRD昰产品流程中的最后一步工作,是将原型中的功能.界面具象化描述,是提交给设计(UI ...
- C# Thread 线程状态知识
.NET 基础类库的System.Threading命名空间提供了大量的类和接口支持多线程.这个命名空间有很多的类.System.Threading.Thread类是创建并控制线程,设置其优先级并获取 ...
- ios程序播放音频文件
1.控制器代码 #import "ViewController.h" #import <AVFoundation/AVFoundation.h> #import &qu ...