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 ...
随机推荐
- 让ASP.NET MVC不使用jsonp也可以跨域访问
跨域问题仅仅发生在Javascript发起AJAX调用,或者Silverlight发起服务调用时,其根本原因是因为浏览器对于这两种请求,所给予的权限是较低的,通常只允许调用本域中的资源,除非目标服务器 ...
- PHP面向对象编程之深入理解方法重载与方法覆盖(多态)
这篇文章主要介绍了PHP面向对象编程之深入理解方法重载与方法覆盖(多态)的相关资料,需要的朋友可以参考下: 什么是多态? 多态(Polymorphism)按字面的意思就是"多种状态" ...
- 序列化悍将Protobuf-Net,入门动手实录
最近在研究web api 2,看了一篇文章,讲解如何提升性能的, 在序列化速度的跑分中,Protobuf一骑绝尘,序列化速度快,性能强,体积小,所以打算了解下这个利器 1:安装篇 谷歌官方没有提供.n ...
- Win10 开发者模式开启
使用注册表方式:建立一个注册表DWORD为1键值:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock\AllowAllTrust ...
- [Linux][VMWare] 学习笔记之安装Linux系统-网络配置
最近开始折腾Linux,在本机装了个VMWare和Centos,装完之后虚拟机里面的OS可以上网,但是使用SecureCRT连接不上虚拟机,开始折腾这个网络. vmware安装好以后,会自动添加两张网 ...
- Codeforces Round #276 (Div. 1) E. Sign on Fence 二分+主席树
E. Sign on Fence Bizon the Champion has recently finished painting his wood fence. The fence consi ...
- URAL 1966 Cycling Roads 点在线段上、线段是否相交、并查集
F - Cycling Roads Description When Vova was in Shenzhen, he rented a bike and spent most of the ...
- 一定要学会paxos算法!
paxos算法 http://blog.csdn.net/dellme99/article/details/14162159
- 启动hbase时出现HMaster Aborted错误
启动hbase时出现 java.lang.RuntimeException: HMaster Aborted at org.apache.hadoop.hbase.master.HMasterComm ...
- Jmeter测试环境搭建(一)
一.工具描述 Apache JMeter是 100%的java桌面应用程序.它可以被用来测试包括基于静态和动态资源程序的性能,例如静态文件,Java Servlets,Java 对象,数据库,F ...