- 浏览: 79619 次
- 性别:
- 来自: 广州
最新评论
-
Tony_Lee-S:
已经说得很明白了吧?“把list强转成Serializable ...
在android中用 Intent 传递 List类型的数据(转) -
zhiduo5:
Activity与Service之间传递参数的介质这个怎么弄啊 ...
在android中用 Intent 传递 List类型的数据(转) -
mathlove:
很有用的内容
一个Android下的自动下载歌词的代码(转)
介绍
有时,我们想在一个window中显示多个视图,这时就需要用到Tab容器。在Android里它叫TabHost。
使用TabHost有两种方式:
1.在相同的activity中使用TabHost导航多个视图
2.使用TabHost导航多个Activity(通过intents)
Tab应用的结构
TabHost的Activity的结构如下:
先看个示例:
layout文件
Activity代码:
1.这里通过TabSpecs类创建Tab
2.使用setIndicator方法设置tab的文字
3.使用setContent设置tab的内容
4.如果你使用TabActivity作为你的Activity的基类,你不用调用TabHost.Setup()方法。
运行后看起来是这样的:
同时还可以指定indicator为一个view:
设置tab的内容
上面的例子展示了使用tab显示不同的layout资源。如果我们需要通过tab导航到不同的Activity,该怎么办?
这种情况,我们需要有一个activity作为应用的根activity。这个Activity包含TabHost,通过intents导航不同的activity。
注意:根Activity必须继承TabActivity。代码如下:
Layout:
Activity:
运行效果
在运行时添加Tab
在运行时我们可以通过调用TabSepc.setContent(TabContentFactory)方法添加Tab。
最终效果:
转自:
http://blog.csdn.net/xinem/article/details/7083523
有时,我们想在一个window中显示多个视图,这时就需要用到Tab容器。在Android里它叫TabHost。
使用TabHost有两种方式:
1.在相同的activity中使用TabHost导航多个视图
2.使用TabHost导航多个Activity(通过intents)
Tab应用的结构
TabHost的Activity的结构如下:
先看个示例:
layout文件
<?xml version="1.0" encoding="utf-8"?> <TabHost android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tabHost" xmlns:android="http://schemas.android.com/apk/res/android" > <TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@android:id/tabs" /> <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@android:id/tabcontent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/tab1" android:orientation="vertical" android:paddingTop="60px" > <TextView android:layout_width="fill_parent" android:layout_height="100px" android:text="This is tab1" android:id="@+id/txt1" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab2" android:orientation="vertical" android:paddingTop="60px" > <TextView android:layout_width="fill_parent" android:layout_height="100px" android:text="This is tab 2" android:id="@+id/txt2" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab3" android:orientation="vertical" android:paddingTop="60px" > <TextView android:layout_width="fill_parent" android:layout_height="100px" android:text="This is tab 3" android:id="@+id/txt3" /> </LinearLayout> </FrameLayout> </TabHost>
Activity代码:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost=(TabHost)findViewById(R.id.tabHost); tabHost.setup(); TabSpec spec1=tabHost.newTabSpec("Tab 1"); spec1.setContent(R.id.tab1); spec1.setIndicator("Tab 1"); TabSpec spec2=tabHost.newTabSpec("Tab 2"); spec2.setIndicator("Tab 2"); spec2.setContent(R.id.tab2); TabSpec spec3=tabHost.newTabSpec("Tab 3"); spec3.setIndicator("Tab 3"); spec3.setContent(R.id.tab3); tabHost.addTab(spec1); tabHost.addTab(spec2); tabHost.addTab(spec3); }
1.这里通过TabSpecs类创建Tab
2.使用setIndicator方法设置tab的文字
3.使用setContent设置tab的内容
4.如果你使用TabActivity作为你的Activity的基类,你不用调用TabHost.Setup()方法。
运行后看起来是这样的:
同时还可以指定indicator为一个view:
TabSpec spec1=tabHost.newTabSpec("Tab 1"); spec1.setContent(R.id.tab1); TextView txt=new TextView(this); txt.setText("Tab 1"); txt.setBackgroundColor(Color.RED); spec1.setIndicator(txt);
设置tab的内容
上面的例子展示了使用tab显示不同的layout资源。如果我们需要通过tab导航到不同的Activity,该怎么办?
这种情况,我们需要有一个activity作为应用的根activity。这个Activity包含TabHost,通过intents导航不同的activity。
注意:根Activity必须继承TabActivity。代码如下:
Layout:
<?xml version="1.0" encoding="utf-8"?> <TabHost android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@android:id/tabhost" xmlns:android="http://schemas.android.com/apk/res/android" > <TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@android:id/tabs" /> <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@android:id/tabcontent" > </FrameLayout> </TabHost>
Activity:
public class TabDemo extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost=getTabHost(); // no need to call TabHost.Setup() //First Tab TabSpec spec1=tabHost.newTabSpec("Tab 1"); spec1.setIndicator("Tab 1",getResources().getDrawable(R.drawable.sun)); Intent in1=new Intent(this, Act1.class); spec1.setContent(in1); TabSpec spec2=tabHost.newTabSpec("Tab 2"); spec2.setIndicator("Tab 2",getResources().getDrawable(R.drawable.chart)); Intent in2=new Intent(this,Act2.class); spec2.setContent(in2); tabHost.addTab(spec2); tabHost.addTab(spec3); } }
运行效果
在运行时添加Tab
在运行时我们可以通过调用TabSepc.setContent(TabContentFactory)方法添加Tab。
<SPAN style="WHITE-SPACE: pre"> </SPAN>TabSpec spec1=tabHost.newTabSpec("Tab 1"); spec1.setIndicator("Tab 1",getResources().getDrawable(R.drawable.sun)); spec1.setContent(new TabContentFactory() { <SPAN style="WHITE-SPACE: pre"> </SPAN> @Override <SPAN style="WHITE-SPACE: pre"> </SPAN> public View createTabContent(String tag) { <SPAN style="WHITE-SPACE: pre"> </SPAN> // TODO Auto-generated method stub <SPAN style="WHITE-SPACE: pre"> </SPAN> return (new AnalogClock(TabDemo.this)); <SPAN style="WHITE-SPACE: pre"> </SPAN> } <SPAN style="WHITE-SPACE: pre"> </SPAN> });
最终效果:
转自:
http://blog.csdn.net/xinem/article/details/7083523
发表评论
-
SQLite多线程读写实践及常见问题总结(转)
2013-02-07 11:04 2962基本操作的部分,大家都很熟悉了,这里根据个人切身经验,总结了 ... -
android内存溢出的解决方法(转)
2013-02-07 11:23 7621. 当项目中包含大量图片,或者图片过大 方法1:等比例缩 ... -
android中的跨进程通信的实现——远程调用过程和aidl(转)
2013-02-07 19:35 1300android在设计理念上强调组件化,组件之间的依赖性很小。 ... -
在EditText/TextView中插入表情图片、样式、下划线等(转)
2012-08-22 12:01 1561EditText: 通常用于显示文字,但有时候也需要在文字中 ... -
自定义Tab选项卡(转)
2012-08-21 08:44 1452效果: 代码: import android.app. ... -
android设置button透明度(转)
2012-08-18 22:09 1196Button或者ImageButton的背景设为透明或者半透明 ... -
Android开发之蓝牙(Bluetooth)操作(二)--修改本机蓝牙设备的可见性,并扫描周围可用的蓝牙设备(转)
2012-08-15 16:54 1348一. 修改本机蓝牙设备的可见性 二. 扫描周围可用的蓝牙设备 ... -
Android开发之蓝牙(Bluetooth)操作(一)--扫描已经配对的蓝牙设备(转)
2012-08-15 16:49 1652一. 什么是蓝牙(Bluetooth)? 1.1 BuleT ... -
一个Android下的自动下载歌词的代码(转)
2012-08-15 13:41 10971. 原理是用Baidu音乐搜索的连接,拼参数进去读取歌词。 ... -
ViewPager多页面滑动切换以及动画效果(转)
2012-08-14 16:55 1847一、首先,我们来看一下效果图,这是新浪微博的Tab滑动效果。我 ... -
Android的Handler总结(转)
2012-08-14 14:18 834一、Handler的定义: 主要接受子线程 ... -
AsyncTask的用法(转)
2012-08-14 14:11 863在开发Android应用时必须遵守单线程模型的原则: Andr ... -
Android逐帧动画(转)
2012-08-13 16:46 1747Android有两种动画,一种是tweened animati ... -
android 扫描SD卡与系统文件(转)
2012-08-11 16:12 1270当手机或模拟器开机时,会调用android的MediaScan ... -
android 怎样为多媒体文件生成缩略图(转)
2012-08-10 17:11 12121、Video 对于视频,取第一帧作为缩略图,也就是怎样从fi ... -
TextView 实现自动换行(转)
2012-08-10 16:44 1362package com.liao.intentservice; ... -
android:屏幕自适应(转)
2012-08-10 16:10 1361demo下载: http://www.eoeandroid.c ... -
listview加载性能优化ViewHolder (转)
2012-07-28 15:16 1421在android开发中Listview是一个很重要的组件,它以 ... -
android 应用程序Activity之间数据传递与共享的几种途径(转)
2012-07-19 11:03 14731.基于消息的通信机制 Intent ---boudle , ... -
Android进程间通信--消息机制及IPC机制实现(转)
2012-07-19 10:51 800一、概念及说明 Android ...
相关推荐
Android 嵌套TabHost示例. 两层TabHost嵌套,实现的效果类似网页上的二级菜单栏。
自定义Android中TabHost组件显示在屏幕底部,并实现滑动切换页面。在此基础上可以实现类似米聊等软件主界面的Tab效果。
Android实现tabHost控件自定义页签页面源码
Android_TabHost_TabWidget选项卡总结
android tabhost activitygroup 源码 分享给有需要的朋友们
Android studio开发,布局TabHost布局 demo,包括修改tab布局: tab栏字体颜色,tab栏大小等布局.
最近在使用TabHost的时候遇到了一些奇怪的问题,在这里总结分享备忘一下。
Android的tabHost案例,适合初学者的Android的tabHost案例,适合初学者,里面有注释,代码清晰明了,导入项目即可使用,亲测可用
介绍Android开发中TabHost(分页卡)的使用。实现TabHost中各个Activity的切换跳转
Android Tabhost 实例demo 自定义Tabhost实现实例。
android 为TabHost添加标签的实现源码,新建一个newTabSpec(newTabSpec),设置其标签和图标(setIndicator),设置内容(setContent),设置TabHost的背景颜色,设置TabHost的背景图片资源,mTabHost....
android tabhost 新浪微博客户端,个人博客http://blog.csdn.net/xianming01关于tabhost的三篇文章的实例。
android 3D Tabhost 旋转 动画 效果,3D旋转的tabhost
androidTabhost的使用实例代码,仅供参考
android Tabhost使用Demo
android TabHost(标签)的使用 简单实例。
Android TabHost动态增加和删除
Android使用tabhost源码
android通过tabhost实现标签页
android 最新的TabHost,不是传统的TabHost,继承了FrameActivity.