Android TabWidget/TabHost有两种使用方法:
第一种:使用系统自带写好的TabHost(及继承自TabActivity类)
第二种:就是定义我们自己的tabHost:不用继承TabActivity
这里我们使用第二章自定义tabHost的方法实现
示例:
main.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="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip">
<TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip">
</FrameLayout>
</LinearLayout>
</TabHost>
Activity.java
public class MainActivity extends TabActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
TabHost tabHost=this.getTabHost();
Intent remoteIntent=new Intent();
remoteIntent.setClass(this, mp3player.class);
//内部类的写法,TabSpec代表一页的内容
TabHost.TabSpec remoteSpec=tabHost.newTabSpec("remote");
//使用android内部的图标,也可以使用自行下载的图片 代表了一页
Resources res=this.getResources();
remoteSpec.setIndicator("remote", res.getDrawable(android.R.drawable.arrow_down_float));
remoteSpec.setContent(remoteIntent);
tabHost.addTab(remoteSpec);
Intent localIntent=new Intent();
localIntent.setClass(this, LocalActivity.class);
TabHost.TabSpec localSpec=tabHost.newTabSpec("local");
localSpec.setIndicator("local", res.getDrawable(android.R.drawable.arrow_down_float));
localSpec.setContent(localIntent);
tabHost.addTab(localSpec);
}
}
分享到:
相关推荐
QT中tabwidget设置tab颜色以及点击选中颜色反转
仿谷歌浏览器的TabWidget,实现Tab右侧的增加按钮,Tab可拖出,拖动时缩略图显示。用VS2012开发
Android TabHost TabWidget 切换卡
使用TabWidget设置不同的标签,每一个标签对应一个界面。点击不同的标签,可以切换到不同的界面
android移动开发总结关于TabWidget切换卡的实现应用
Android_TabHost_TabWidget选项卡总结
http://blog.csdn.net/birdno1/article/details/50516725 通过自定义view解决tabwidget下划线颜色问题
android tabwidget 嵌套的使用,主要在子页面中也能很好的实现界面的切换
PYQT 实现TabWidget 双击关闭功能 soeasy
TabWidget实现不同Activity的切换
TabHost+TabWidget+FrameLayout实现主页面实现底部栏;
TabWidget控件.
TabWidget范例
qt程序 tabWidget tab页左侧排列,文字横向排列
QT 扁平化界面风格,看起来很像移动端的界面,大气,扁平化走起
动态获得添加数据量,实现实时添加删除操作,自定义了Combox和spin实现combox中有多个spinBox,实现功能。动态添加删除数据信息,备注都是全的,详细讲解
自定义样式的tabHost,包含两种方式:activity对象作为内容、View对象作为内容。注释详细
本文实例讲述了Android切换卡TabWidget用法。分享给大家供大家参考,具体如下: Tab选项卡类似与电话本的界面,通过多个标签切换不同的内容,要实现这个效果,首先要知道TabHost,它是一个用来存放多个Tab标签的容器...
android 切换卡 TabWidget