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的更多相关文章

  1. Android tabhost下的activity怎样获取传来的值

    android tabhost下的activity怎样获取传来的值,具体解决方案如下: 解决方案: 其他activity设置intent:Intent intent=new Intent(); int ...

  2. Android - TabHost 与 Fragment 制作页面切换效果

    Android - TabHost 与 Fragment 制作页面切换效果 Android API 19 , API 23 三个标签页置于顶端 效果图: 在文件BoardTabHost.java中定义 ...

  3. Android——TabHost(标签容器)相关知识总结贴

    android 2.3 r1 中文 api (58) —— TabHost http://www.apkbus.com/android-18911-1-1.html   android中文api (5 ...

  4. Android TabHost使用

    TabHost是Android中自带的选项卡控件,效果图如下: 主布局文件 <RelativeLayout xmlns:android="http://schemas.android. ...

  5. Android -- TabHost、Fragment、状态保存、通信

    工程结构                                                                                       TabAFm到Ta ...

  6. Android TabHost中Activity之间传递数据

    例子1: TabHost tabhost = (TabHost) findViewById(android.R.id.tabhost); tabhost.setup(this.getLocalActi ...

  7. Android TabHost 动态修改图标或者动态改变标题

    那时客户需要实现在TabHost标题上动态显示从数据库获取的个数.起初这样思考的,从数据库 获取个数是非常简单,但是要把获取的个数显示在TabHost标题,思前想后,想用Handler来异步实现消息传 ...

  8. Android TabHost中实现标签的滚动以及一些TabHost开发的奇怪问题

    最近在使用TabHost的时候遇到了一些奇怪的问题,在这里总结分享备忘一下. 首先说一点TabActivity将会被FragmentActivity所替代,但是本文中却是使用的TabActivity. ...

  9. Android TabHost TabWidget 去除黑线(底部下划线)

    采用TabHost布局时,往往会发现默认的系统风格与软件风格很不协调,比如TabWidget的下划线影响布局效果.通常情况下会去除其下划线.如果是采用xml布局文件,在TabWidget的属性项设置a ...

随机推荐

  1. SQL高级查询技巧(两次JOIN同一个表,自包含JOIN,不等JOIN)

    掌握了这些,就比较高级啦 Using the Same Table Twice 如下面查询中的branch字段 SELECT a.account_id, e.emp_id, b_a.name open ...

  2. LINQ To DataSet 示例

    如果在项目遇到这样的问题如:DataTable1和DataTable2需要根据一定的规则进行合并成一个DataTable3. 问题1:DataTable1不是读数据库表的结果,而是合成的数据集,因此无 ...

  3. Solr入门之(6)配置文件solrconfig.xml

    solrconfig.xml包含了用于配置自身行为的绝大部分参数,其作用范围是当前core.该文件位于${solr_home}/solr/core1/conf/下. 参数列表概览: A.lib B.d ...

  4. thinkphp自动验证中的静态验证和动态验证和批量验证

    1.静态定义 在模型类里面预先定义好该模型的自动验证规则,我们称为静态定义. 举例说明,我们在模型类里面定义了$_validate属性如下: class UserModel extends Model ...

  5. hdu 4741 2013杭州赛区网络赛 dfs ***

    起点忘记录了,一直wa 代码写的很整齐,看着很爽 #include<cstdio> #include<iostream> #include<algorithm> # ...

  6. 无法启动程序 ”*.lib”

    解决办法: 把含有入口函数(main函数)的 工程 如 cpp-test 设置为启动项 具体操作: 选中 cpp-test 工程 右击 —> 设为启动项目

  7. 无法定位程序输入点 _glutCreateWindowWithExit于动态链接库glut32.dll上

    程序运行提示错误"无法定位程序输入点 _glutCreateWindowWithExit于动态链接库glut32.dll上",网上查了说是opengl的.lib和.dll版本过低, ...

  8. [荐]使用jQuery清空file文件域

    file是文本域,我们一般都会使用它来上传文件,在上传文件时我们需要验证,验证完成后,如果存在错误,为了防止将错误信息也上传上去,我们总是希望能够将其清空.但是在IE中,为了安全起见它是不允许我们改变 ...

  9. 出来ios顶部导航掉下来问题

    <script type="text/javascript"> setposition(); function setposition(){ var ua = navi ...

  10. 原生JavaScript 全特效微博发布面板效果实现

    javaScript实现微博发布面板效果.---转载白超华 采用的js知识有: 正则表达式区分中英文字节.随机数生成等函数 淡入淡出.缓冲运动.闪动等动画函数 onfocus.onblur.oninp ...