Android——TabWidget
1、activity_tabwidget.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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/tb_tv1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="This is the first tab" />
<TextView
android:id="@+id/tb_tv2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="This is another tab" />
<TextView
android:id="@+id/tb_tv3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="This is the third tab" />
</FrameLayout>
</LinearLayout>
</TabHost>
2、TabWidgetActivity.java
public class TabWidgetActivity extends TabActivity {
// 声明TabHost对象
TabHost tabHost;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tabwidget);
try {
// 取得TabHost对象
tabHost = getTabHost();
/* 为TabHost添加标签 */
// 新建一个newTabSpec(newTabSpec)
// 设置其标签和图标(setIndicator)
// 设置内容(setContent)
tabHost.addTab(tabHost
.newTabSpec("tab_test1")
.setIndicator("TAB1",
getResources().getDrawable(R.drawable.button1))
.setContent(R.id.tb_tv1));
tabHost.addTab(tabHost
.newTabSpec("tab_test2")
.setIndicator("TAB2",
getResources().getDrawable(R.drawable.button2))
.setContent(R.id.tb_tv2));
tabHost.addTab(tabHost.newTabSpec("tab_test3").setIndicator("TAB3",
getResources().getDrawable(R.drawable.button3)).setContent(R.id.tb_tv3));
// 设置TabHost的背景颜色
tabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));
// 设置TabHost的背景图片资源
tabHost.setBackgroundResource(R.drawable.ic_launcher);
// 设置当前显示那一个标签
tabHost.setCurrentTab(0);
} catch (Exception e) {
e.printStackTrace();
}
// 标签切换事件处理
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
Dialog dialog = new AlertDialog.Builder(TabWidgetActivity.this)
.setTitle("提示")
.setMessage("当前选中" + tabId + "标签")
.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int whichButton) {
dialog.cancel();
}
}).create();
dialog.show();
}
});
}
}
Android——TabWidget的更多相关文章
- Android TabWidget底部显示
TabHost控件默认使用LinearLayout包裹TabWidget和FrameLayout,布局文件如下: <TabHost xmlns:android="http://sche ...
- ANDROID中去掉ACTIONBAR或TABWIDGET的分隔线
在android中,有时需要对ActionBar或者TabWidget的分隔线进行定制,如取消,相关的属性设置为android:divider 以TabWidget为例,取消对应的函数: tabWid ...
- Android 实现分页(使用TabWidget/TabHost)
注:本文为转载,但该内容本人已亲身尝试,确认该方法可行,代码有点小的改动,转载用作保存与分享. 原作者地址:http://gundumw100.iteye.com/blog/853967 个人吐嘈:据 ...
- Android Tab -- 使用TabWidget、TabHost、TabActivity来实现
原文地址:http://blog.csdn.net/crazy1235/article/details/42678877 TabActivity在API13之后被fragment替代了,所以不建议使用 ...
- android开发之如何使TabHost的TabWidget位于屏幕下方
更改TabHost里的第一个LinearLayout为RelativeLayout.并在TabWidget中添加android:layout_alignParentBottom="true& ...
- Android:简单实现ViewPager+TabHost+TabWidget实现导航栏导航和滑动切换
viewPager是v4包里的一个组件,可以实现滑动显示多个界面. android也为viewPager提供了一个adapter,此adapter最少要重写4个方法: public int getCo ...
- android自定义TabWidget样式
先看看效果图吧,个人觉得图标丑了点,不过还行,自己用PS做的 下面是全部代码和流程,一定要按流程顺序来,不然错误! 1.tabhost.xml <TabHost xmlns:android=&q ...
- Android TabHost TabWidget 去除黑线(底部下划线)
采用TabHost布局时,往往会发现默认的系统风格与软件风格很不协调,比如TabWidget的下划线影响布局效果.通常情况下会去除其下划线.如果是采用xml布局文件,在TabWidget的属性项设置a ...
- android之TabWidget选项卡
1 概览 l TabWidget与TabHost.tab组件一般包括TabHost和TabWidget.FrameLayout,且TabWidget.FrameLayout属于TabHost. l ...
随机推荐
- css3写出0.5px的边框
一说到0.5px的边框,我们一般认为是不行的,因为在ps中0.5px的线也是做不出来的,这个计算机的像素有关系. 废话不多说了,0.5px 其实用的是css3新特性,box-shadow:阴影设置 代 ...
- js 删除DropDownList的选项
function del_DropDownList_Option() { var ddlXZ= document.getElementById("name&quo ...
- memcache 永久数据被踢
1.memcache的slab chunk 就像公交车的坐位一样,有大小之分,还有活跃的状态. 2.代码 index.php -->插入数据,注意$value的大小和重复次数,跟chunk和其数 ...
- 使用水晶报表更新后出现“值不能为 null。 参数名: inputString”
简单记录一下: 如果更新完水晶报表相关页面可能在原来页面刷新会出现错误:"值不能为 null. 参数名: inputString",如图:
- 一个 IT 青年北漂四年的感悟
转载自:http://www.codeceo.com/article/it-man-beijing-4-years.html 工作这几年,每年都会有朋友离开北京,每次朋友跟我告别的时候总是让我有很多感 ...
- 黄聪:wordpress更新失败‘C:\Windows\TEMP/wordpress.tmp’,更换临时保存路径的解决办法
1.如果可劲进入远程桌面,则给C:\WINDOWS\TEMP目录设置IIS访问权限. 2.虚拟机的方法:首先用FTP软件在网页空间wp-content目录中新建一个[tmp]目录,然后在wp-conf ...
- setValue:forUndefinedKey
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewControlle ...
- git 使用详解(8)-- tag打标签
打标签 同大多数 VCS 一样,Git 也可以对某一时间点上的版本打上标签.人们在发布某个软件版本(比如 v1.0 等等)的时候,经常这么做.本节我们一起来学习如何列出所有可用的标签,如何新建标签,以 ...
- DBA_Oracle海量数据处理分析(方法论)
2014-12-18 Created By BaoXinjian
- PLSQL_性能优化系列18_Oracle Explain Plan解析计划通过Baseline绑定
2015-05-28 Created By BaoXinjian