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. 图结构练习——最小生成树(prim算法(普里姆))

      图结构练习——最小生成树 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述  有n个城市,其中有些城市之间可以修建公路,修建不同 ...

  2. wp8 入门到精通 数据库更新字段(一)

    public class UserInfoDB : BaseDB { public UserInfoDB() : base(@"Data Source=isostore:\MakeLove\ ...

  3. hdu 5294 最短路+最大流 ***

    处理处最短路径图,这个比较巧妙 链接:点我

  4. 使用AStyle进行代码格式化

    转自:http://www.cnblogs.com/JerryTian/archive/2012/09/20/AStyle.html 在日常的编码当中,大家经常要遵照一些设计规范,如命名规则.代码格式 ...

  5. 搜索 录音功能 Android api

    搜索 录音功能 Android api http://www.oschina.net/android/47/ http://m.blog.csdn.net/blog/u011309801/406523 ...

  6. 串口编程 tcflush()函数 (转)

    tcflush函数刷清(扔掉)输入缓存(终端驱动法度已接管到,但用户法度尚未读)或输出缓存(用户法度已经写,但尚未发送). int tcflush(int filedes,int quene)  qu ...

  7. poj 1816 (Trie + dfs)

    题目链接:http://poj.org/problem?id=1816 思路:建好一颗Trie树,由于给定的模式串可能会重复,在原来定义的结构体中需要增加一个vector用来记录那些以该节点为结尾的字 ...

  8. Java反射详解及应用示例

    反射是Java中最重要的内容之一,了解反射原理对我们学习各种框架具有很大的帮助 反射的原理: 反射应用示例: import java.lang.reflect.Constructor; import ...

  9. AChartEngine使用View显示图表

    学习过AChartEngine的人肯定都知道,使用ChartFactory创建一张图表可以使用Intent方法,之后调用StartActivity来启用这个Intent,但是这么左右一个坏处,就是当你 ...

  10. host_network_interfaces_slow_mode_thresholds

    CDH报集群异常: host_network_interfaces_slow_mode_thresholds 警告置为从不-- 主要是我没有查到发生这种情况的原因是什么--