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 ...
随机推荐
- spring配置中,properties文件以及xml文件配置问题
spring方便我们的项目快速搭建,功能强大,自然也会是体系复杂! 这里说下配置文件properties管理的问题. 一些不涉及到代码逻辑,仅仅只是配置数据,可以放在xxxx.properties文件 ...
- 【linux】top命令详解
常用命令 top -d 3 ##每3秒监控一次 [root@TG1704 log]# top top - 14:06:23 up 70 days, 16:44, 2 users, load avera ...
- laravel5-目录结构分析
laravel5-目录结构分析 (2016-01-21 11:24:03) 转载▼ 一.环境配置: $ lsb_release -a No LSB modules are available. ...
- IntelliJ IDEA中如何设置同时打开多个文件且分行显示?
Window→Editor Tabs→Tabs Placement→Show Tabs in Single Row 取消选中后即可在多行显示 下图为实际显示效果: 还可以自行设置打开文件窗口数(默认 ...
- golang rbac框架
在 https://github.com/mikespook/gorbac/tree/v1.0 github上新的版本是开发板,得用这里的老版 demo package main import ( & ...
- linux下查看系统进程占用的句柄数
---查看系统默认的最大文件句柄数,系统默认是1024 # ulimit -n 1024 ----查看当前进程打开了多少句柄数 # lsof -n|awk '{print $2}'|sort|uniq ...
- libcurl上传文件,添加自定义头
原文 http://www.cnblogs.com/meteoric_cry/p/4285881.html 主题 curl libcurl参数很多,一不小心就容易遇到问题.曾经就遇到过一个很蛋疼的问 ...
- Titan-红号楼宗谱案例
一. 简介 titan:存储,查询图形结构的数据库.分布式集群环境下,可支持数以千亿级别的点和边,同时支持上千个并发的实时的复杂图形遍历,支持ACID事务. 架构:支持以下3方面的自由组合 (1)节点 ...
- PLSQL_闪回操作1_Flashback Query
2014-07-02 Created By BaoXinjian
- OAF_EO系列1 - Definition定义(概念)
2014-06-14 Created By BaoXinjian