Android之TabHost
来源:互联网 发布:utorrent mac版中文版 编辑:程序博客网 时间:2024/05/16 04:58
一. 简单示例
src
public class AndroidUIActivity extends TabActivity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);// tabHost是一个标签容器TabHost tabHost = this.getTabHost();// 每一个TabSpec对象就是个标签// TabSpec.setIndicator()方法是设置标签显示样式// TabSpec.setContent()方法显示标签下方的内容显示// 定义第一个标签tabHost.addTab(tabHost.newTabSpec("OneTab").setIndicator("OneTab",getResources().getDrawable(android.R.drawable.star_on)).setContent(R.id.linearLayout1));// 定义第二个标签tabHost.addTab(tabHost.newTabSpec("TwoTab").setIndicator("TwoTab",getResources().getDrawable(android.R.drawable.star_off)).setContent(R.id.linearLayout2));// 定义第三个标签tabHost.addTab(tabHost.newTabSpec("ThreeTab").setIndicator("ThreeTab",getResources().getDrawable(android.R.drawable.stat_notify_call_mute)).setContent(R.id.linearLayout3));}}
main.xml
<?xml version="1.0" encoding="utf-8"?><!-- 根元素是 TabHost ,我们这个文件要和TabActivity配合使用,在TabActivity的源代码里写死了要找的Id是android.R.id.tabhost,因此这里的ID也要定死成TabHost 的ID 是定死的 "@android:id/tabhost" 下面的类似,不再解释。--><TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="wrap_content" > <!-- TabWidget 就是标签选项卡的头部部分,注意ID的写法 --> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" > </TabWidget> <!-- FrameLayout 就是标签的内容显示部分,注意ID的写法,还要注意我们做了个上部空白设定 android:paddingTop="65dp",是为了不让内容和标签重叠 --> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" > <!-- LinearLayout 是一个标签里的内容,程序根据你定义的ID来把他们放在不同的标签下面 android:paddingtop="65dp" --> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="标签1中的内容" > </TextView> </LinearLayout> <!-- LinearLayout 是另一个标签里的内容 --> <LinearLayout android:id="@+id/linearLayout2" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="标签2中的内容" > </TextView> </LinearLayout> <LinearLayout android:id="@+id/linearLayout3" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="标签3中的内容" > </TextView> </LinearLayout> </FrameLayout></TabHost>
二. 运行结果
启动
点击ThreeTab
- Android开发之TabHost
- Android之TabHost
- android之TabHost
- android 之 TabHost
- android控件之TabHost
- Android之TabHost布局
- Android控件之TabHost
- Android之TabHost
- Android控件之TabHost
- android学习之-TabHost
- Android之TabHost
- Android之TabHost
- Android 之TabHost
- Android之TabHost
- Android之TabHost布局
- android之tabhost讲解
- Android控件之TabHost
- Android 之 TabHost
- gnuplot 画折线图
- Linux操作系统中的七件超厉害的武器
- LinuxThread VS NPTL
- Android小知识点
- java常用代码分享
- Android之TabHost
- POJ图论题目
- 用jxl读取excel
- 动态修改Label显示,通过信号实时刷新
- 恩智浦智能照明让每个灯泡拥有一个IP
- Mysql command
- sqlplus显示中文为乱码, 对注册表下面的健值进行改动 ----解决中文显示问题
- [IT 男人帮 11-07] Vim:祝你 20 岁生日快乐
- Word/Excel/PDF文件转换成HTML整理