Android之TabHost
来源:互联网 发布:mac rar文件 编辑:程序博客网 时间:2024/06/17 05:36
TabHost可以实现tab的效果
1、编写tabhost.xml
<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <FrameLayout android:id="@android:id/tabcontent" //注意id的写法,表示放置内容 android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" > <LinearLayout android:id="@+id/l1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第一页" /> </LinearLayout> <LinearLayout android:id="@+id/l2" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第二页" /> </LinearLayout> <LinearLayout android:id="@+id/l3" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第三页" /> </LinearLayout> </FrameLayout> <TabWidget android:id="@android:id/tabs" //注意id,表示标签 android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout></TabHost>
2、对应的Java代码
package org.zqy.andr;import android.os.Bundle;import android.app.TabActivity;import android.widget.ImageView;import android.widget.TabHost;import android.widget.TabHost.TabSpec;public class TabHostActivity extends TabActivity {private TabHost th;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.tabhost);ImageView img = new ImageView(TabHostActivity.this);img.setImageResource(R.drawable.ic_launcher);th = getTabHost();TabSpec ts1 = th.newTabSpec("tab1").setIndicator("项目一",getResources().getDrawable(R.drawable.ic_launcher)).setContent(R.id.l1);TabSpec ts2 = th.newTabSpec("tab2").setIndicator(img).setContent(R.id.l2);TabSpec ts3 = th.newTabSpec("tab3").setIndicator("项目三",getResources().getDrawable(R.drawable.ic_launcher)).setContent(R.id.l3);th.addTab(ts1);th.addTab(ts2);th.addTab(ts3);th.setCurrentTab(2);//指定默认进入的tab}}
运行结果:
- 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
- C语言 之 栈
- JDK环境变量配置
- Documentation/ABI/obsolute/sys-bus-usb.txt
- codeblocks 调试不停止的解决办法。
- 关于vc6程序拖拽文件WM_DROPFILE在win7,win8,vista上不能响应的解决方法
- Android之TabHost
- C语言 之 文件
- LTE射频拉远单元数字中频方案(七)
- 一元二次方程求解
- 顺序存储转为链接存储(二叉树)
- poj 2699 The Maximum Number of Strong Kings 网络流
- 分布式大作业p2p聊天室
- Android Fragment应用实战,使用碎片向ActivityGroup说再见
- 积累的VC编程--图标、光标及位图(转)