<TabHost> 简单使用
来源:互联网 发布:手机淘宝评价怎么删 编辑:程序博客网 时间:2024/05/17 08:06
注意该类继承的是 TabActivity
package com.crazyit.ui.tabhostdemo;import android.app.TabActivity;import android.os.Bundle;import android.widget.TabHost;/** * TabHost的 使用 */public class TabHostActivity extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tab_host); //获取该 activity里面的 TabHost TabHost tabHost = getTabHost(); //创建第一个 tab页 TabHost.TabSpec tab1 = tabHost.newTabSpec("tab1"). setIndicator("已接电话")//设置标题 .setContent(R.id.tab01); //设置内容 //添加第一个 tab 标签页 tabHost.addTab(tab1); TabHost.TabSpec tab2 = tabHost.newTabSpec("tab2") .setIndicator("呼出电话",getResources().getDrawable(R.mipmap.ic_launcher)) .setContent(R.id.tab02); //添加第2个 tab标签页 tabHost.addTab(tab2); //创建第3个标签页 TabHost.TabSpec tab3 = tabHost.newTabSpec("tab3") .setIndicator("已接电话") .setContent(R.id.tab03); //添加 第3个标签页 tabHost.addTab(tab3); }}
布局文件
<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@android:id/tabhost" //注意此处的 id 是引用Android系统自己的 不是开发人员自己定义的 android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" tools:context="com.crazyit.ui.tabhostdemo.TabHostActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- tab标题--> <TabWidget android:id="@android:id/tabs" //注意此处的 id 是引用Android系统自己的 不是开发人员自己定义的 android:layout_width="match_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" //注意此处的 id 是引用Android系统自己的 不是开发人员自己定义的 android:layout_width="match_parent" android:layout_height="match_parent"> <!--定义第一个标签页的内容--> <LinearLayout android:id="@+id/tab01" android:gravity="center" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="八部天龙" android:textSize="22dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="东海三太子" android:textSize="22dp" /> </LinearLayout> <!--定义第2个标签页的内容--> <LinearLayout android:id="@+id/tab02" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="斗战圣佛" android:textSize="22dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="花果山水帘洞" android:textSize="22dp" /> </LinearLayout> <!--定义第3个标签页的内容--> <LinearLayout android:id="@+id/tab03" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="净坛使者" android:textSize="22dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="天蓬元帅" android:textSize="22dp" /> </LinearLayout> </FrameLayout> </LinearLayout></TabHost>
- TabHost容器 需要两个组件 TabWidget和 Framelayout
- FrameLayout 用于 层叠组合多个选项卡
- 布局文件的 id也是有要求的
- TabHost 的 ID 为@android:id/tabhost
- TabWidget的 ID为 @android:id/tabs
- FrameLayout的 Id @android:id/tabcontent
0 0
- TabHost简单使用
- Tabhost的简单使用
- tabHost的简单使用
- TabHost简单使用示例
- Tabhost的简单使用
- <TabHost> 简单使用
- tabhost简单使用及tabhost源码分析
- tabhost简单使用及tabhost源码分析
- Android---61---TabHost简单使用
- TabHost空间的简单使用
- tabHost选项卡的简单使用
- Tabhost使用
- TabHost使用
- TabHost使用
- Andriod TabHost的使用TabHost
- 简单的TabHost
- TabHost 简单使用方法
- Tabhost的简单运用
- 如何使用 sbt 下载项目的依赖包的源码
- 开始
- 第10周 C语言及程序设计提高例程-40 小小型应用系统开发指导(四)
- Eclipse新建工程没有minGW
- iOS cocos2d的安装和卸载
- <TabHost> 简单使用
- 软件的分享、卸载、详细信息、运行的代码实现
- ServletConfig与ServletContext对象详解
- Android程序崩溃重启
- TCP滑动窗口机制
- GCC升级问题解决:configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.,mpfr2.4.0
- A poor simple sample to perfectly introduce how to program in CUDA
- AdapterView之ListView简介
- SICP 练习1.39 计算tan(x)