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. Python 反编译工具uncompyle2

    如何反编译pyc uncompyle2 是一个可以将pyc文件转换为py源码的工具 下载地址:https://github.com/wibiti/uncompyle2 安装: setup.py ins ...

  2. 排队打饭 sdut 2443【最简单的贪心法应用举例】

    排队打饭 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 题目链接:http://acm.sdut.edu.cn/sdutoj/p ...

  3. WinDbg 命令三部曲:(一)WinDbg 命令手册

    本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 系列博文 <WinDbg 命令三部曲:(一)WinDbg 命令手册> <WinDb ...

  4. HDU1899 Sum the K-th's(树状数组)

    枚举,每次增加点,删除点 #include<cstdio> #include<iostream> #include<cstdlib> #include<cst ...

  5. wp8 入门到精通 Gallery

    <Grid x:Name="LayoutRoot" Background="Transparent"> <Grid.Resources> ...

  6. 腾讯微博的账号登录及api操作

    .tqq.php <?php /** * PHP Library for t.qq.com * * @author */ class tqqPHP { function __construct( ...

  7. 在linux配置NFS用于RAC的搭建

    rac的共享存储有很多种搭建方式,nfs是其中一种.生产环境一般不采用nfs,多用于测试. nfs搭建步骤大致分为如下: 1.划盘 给节点1挂载一块磁盘,并将磁盘分区,并格式化,再挂载 [root@n ...

  8. Eclipse调试方法及快捷键

    基本操作 断点,breakpoint: F5键与F6键均为单步调试: F5是step into,也就是进入本行代码中执行,跳入 F6是step over,跳过,也就是执行本行代码,跳到下一行 F7是跳 ...

  9. HDU 5787 K-wolf Number 数位DP

    K-wolf Number Problem Description   Alice thinks an integer x is a K-wolf number, if every K adjacen ...

  10. theano报一种float类型错误的处理办法

    我实际用的环境是Keras,查错误时查到是Theano的配置问题,所以在标题里就写成Theano的问题了, 是这样的,从Github上下载的别人的代码,准备复现别人的实验,结果在机器上部署好环境之后跑 ...