tabhost的一种用法
来源:互联网 发布:淘宝店如何分销 编辑:程序博客网 时间:2024/05/12 12:44
第一步配置布局文件
01
<
TabHost
02
android1:id
=
"@android:id/tabhost"
03
android1:layout_width
=
"match_parent"
04
android1:layout_height
=
"match_parent"
05
android1:layout_weight
=
"1"
>
06
07
<
LinearLayout
08
android1:layout_width
=
"match_parent"
09
android1:layout_height
=
"match_parent"
10
android1:orientation
=
"vertical"
>
11
12
<
TabWidget
13
android1:id
=
"@android:id/tabs"
14
android1:layout_width
=
"match_parent"
15
android1:layout_height
=
"wrap_content"
>
16
</
TabWidget
>
17
18
<
FrameLayout
19
android1:id
=
"@android:id/tabcontent"
20
android1:layout_width
=
"match_parent"
21
android1:layout_height
=
"match_parent"
>
22
23
<
LinearLayout
24
android1:id
=
"@+id/tab1"
25
android1:layout_width
=
"match_parent"
26
android1:layout_height
=
"match_parent"
>
27
28
<
ListView
29
android1:id
=
"@+id/listview1"
30
android1:layout_width
=
"fill_parent"
31
android1:layout_height
=
"fill_parent"
>
32
</
ListView
>
33
</
LinearLayout
>
34
35
<
LinearLayout
36
android1:id
=
"@+id/tab2"
37
android1:layout_width
=
"match_parent"
38
android1:layout_height
=
"match_parent"
>
39
</
LinearLayout
>
40
</
FrameLayout
>
41
</
LinearLayout
>
42
</
TabHost
>
1
<
LinearLayout
2
android1:id
=
"@+id/tab2"
3
android1:layout_width
=
"match_parent"
4
android1:layout_height
=
"match_parent"
>
5
</
LinearLayout
>
在linearlayout中设置你需要的控件,我这里放了一个listview
第二步 配置activity
1
final
TabHost tabhost = (TabHost) findViewById(android.R.id.tabhost);
2
tabhost.setup();
3
TabWidget tabwidget = tabhost.getTabWidget();
4
tabhost.addTab(tabhost.newTabSpec(
"tab1"
).setIndicator(
"tab1"
)
5
.setContent(R.id.tab1));
6
tabhost.addTab(tabhost.newTabSpec(
"tab2"
).setIndicator(
"tab2"
)
7
.setContent(R.id.tab2));
第三步 事件监听
01
tabhost.setOnTabChangedListener(
new
OnTabChangeListener() {
02
public
void
onTabChanged(String arg0) {
03
// TODO Auto-generated method stub
04
Toast.makeText(DiquActivity.
this
,
"当前标签页为"
+ arg0,
05
Toast.LENGTH_SHORT).show();
06
}
07
});
08
09
tabhost.getTabWidget().getChildAt(
0
)
10
.setOnClickListener(
new
OnClickListener() {
11
12
@Override
13
public
void
onClick(View v) {
14
// TODO Auto-generated method stub
15
tabhost.setCurrentTab(
0
);
16
Toast.makeText(DiquActivity.
this
,
"当前标签页为1"
,
17
Toast.LENGTH_SHORT).show();
18
}
19
});
20
21
tabhost.getTabWidget().getChildAt(
1
)
22
.setOnClickListener(
new
OnClickListener() {
23
24
@Override
25
public
void
onClick(View v) {
26
// TODO Auto-generated method stub
27
tabhost.setCurrentTab(
1
);
28
Toast.makeText(DiquActivity.
this
,
"当前标签页为2"
,
29
Toast.LENGTH_SHORT).show();
30
}
31
});
0 0
- tabhost的一种用法
- TabHost的用法
- tabHost的相关用法
- Android TabHost的用法
- TabHost的用法
- TabHost的用法
- TabHost的用法
- android tabhost的用法
- TabHost的用法
- Tabhost的用法
- TabHost的用法
- TabHost便签的用法
- Tabhost的简单用法
- Android TabHost的用法浅析
- android中TabHost的用法
- TabHost的两种用法
- TabHost TabWidget的简单用法
- android 简单tabHost的用法
- Linux快捷键
- 内存cookie与持久cookie
- JSP自定义标签<base>
- 翻译 - JavaScript之鼠标滚动事件
- 网页数据采集:[3]python如何利用抓包数据
- tabhost的一种用法
- Qt QDialog对话框 模态&非模态
- java 调用 keytool 生成keystore 和 cer 证书
- 网页数据采集:[2]httpwatch抓包教程详解
- C#对DataTable数据排序,检索,合并
- duilib进阶教程 -- 实现List排序
- 发邮件的礼仪汇总---让优秀成为习惯
- tomcat 7--connector
- Vmware的三种网络连接模式(bridged、NAT、host-only)区别