TabHost的使用
来源:互联网 发布:数据库获取系统时间 编辑:程序博客网 时间:2024/06/03 08:26
有两种方式可以实现 TabHost 。一种是直接使用 TabActivity ,一种是不使用 TabActivity 。
使用TabActivity实现TabHost
1.strings.xml
<resources> <string name="app_name">TestActivity</string> <string name="menu_settings">Settings</string> <string name="title_activity_main">MainActivity</string> <string name="tab1">选项卡1</string> <string name="tab2">选项卡2</string> <string name="tab3">选项卡3</string> </resources>
2.main.xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/black" > <LinearLayout android:id="@+id/tab1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_horizontal"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="24dip" android:text="@string/tab1"/> </LinearLayout> <LinearLayout android:id="@+id/tab2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_horizontal"> <TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="24dip" android:text="@string/tab2"/> </LinearLayout> <LinearLayout android:id="@+id/tab3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_horizontal"> <TextView android:id="@+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="24dip" android:text="@string/tab3"/> </LinearLayout> </FrameLayout>
3.Activity
package com.example.testactivity; import android.app.TabActivity; import android.os.Bundle; import android.view.LayoutInflater; import android.widget.TabHost; public class MainActivity extends TabActivity { private TabHost myTabHost; protected void onCreate(Bundle icicle) { super.onCreate(icicle); // setContentView(R.layout.main); //1.获取该 Activity 用于容纳 tab 的 TabHost 对象 myTabHost=this.getTabHost(); //2.获取 LayoutInftelar 对象 LayoutInflater inflater=LayoutInflater.from(this); //3。将 main.xml 的内容,嵌入到 myTabhost.getTabContentView() 所返回的 FrameLayout 中 inflater.inflate(R.layout.main, myTabHost.getTabContentView(), true); /** 给 tabhost 增加 tab newTabSpec(String tag) 返回一个 TabHost.TabSpec 对象,其参数用于标识一个 tab 的 tag ,为 String 类型 setIndicator(" "): 显示 tab 上的文字 setContent(int ) :指定 tab 的内容,必须为 id ,比如空间的 id 或者 layout 的 id*/ myTabHost.addTab( myTabHost.newTabSpec("通话记录") .setIndicator("通话记录",getResources().getDrawable(android.R.drawable.ic_dialog_alert)) .setContent(R.id.tab1)); myTabHost.addTab( myTabHost.newTabSpec("收藏") .setIndicator("收藏",getResources().getDrawable(android.R.drawable.ic_dialog_info)) .setContent(R.id.tab2)); myTabHost.addTab( myTabHost.newTabSpec("拨号") .setIndicator("拨号",getResources().getDrawable(android.R.drawable.ic_dialog_dialer)) .setContent(R.id.tab3)); setContentView(myTabHost); } }
程序运行截图
- Andriod TabHost的使用TabHost
- Android TabHost的使用
- Android TabHost的使用
- TabActivity & TabHost 的使用
- Android TabHost的使用
- Tabhost的使用
- Android TabHost的使用
- android Tabhost的使用
- TabHost的使用
- Android TabHost的使用 .
- Android TabHost的使用
- Android TabHost的使用
- TabHost的使用
- TabHost的使用
- TabHost的使用
- Tabhost的简单使用
- TabHost的使用
- TabHost的使用
- 风尘中,忘了捡拾那日女子留下的胭脂
- hdu 3530 dp + 单调队列优化
- 求职那些事四
- Android MID 3G 移植
- 在含有Struts2框架的应用中添加KindEditor上传图片功能
- TabHost的使用
- 14岁初中生—— 踏踏实实的人生也最美
- Android图形动画概述
- OK6410之ADC驱动硬件分析---阻塞与非阻塞IO
- JS 学习笔记--Object对象
- Android高手进阶教程(二十八)之---Android ViewPager控件的使用(基于ViewPager的横向相册)!!!
- Ubuntu下配置一个高效的PHP开发环境GVIM
- Android高手进阶教程(二十七)之---基于ViewFlipper实现的自定义新手指引控件.
- GPU深度发掘(四)::Render to Vertexbuffer in OpenGL