初识选项卡 TabHost
来源:互联网 发布:nginx配置ssl证书 编辑:程序博客网 时间:2024/05/26 17:49
第一种:
public class Tab01 extends TabActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabHost = getTabHost();
LayoutInflater.from(this).inflate(R.layout.tabs1, tabHost.getTabContentView(), true);
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("tab1")
.setContent(R.id.view1));
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("tab2")
.setContent(R.id.view2));
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("tab3")
.setContent(R.id.view3));
}
}
第二种:
public class Tabs2 extends TabActivity implements TabHost.TabContentFactory {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("tab1", getResources().getDrawable(R.drawable.star_big_on))
.setContent(this));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("tab2")
.setContent(this));
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("tab3")
.setContent(this));
}
/** {@inheritDoc} */
public View createTabContent(String tag) {
final TextView tv = new TextView(this);
tv.setText("Content for tab with tag " + tag);
return tv;
}
}
第三种:
public class Tabs3 extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("list")
.setContent(new Intent(this, List1.class)));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("photo list")
.setContent(new Intent(this, List8.class)));
// This tab sets the intent flag so that it is recreated each time
// the tab is clicked.
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("destroy")
.setContent(new Intent(this, Controls2.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
}
}
总结一下:
1、都要继承TabActivity,以便通过getTabHost()得到TabHost对象
2、通过addTab添加选项,其中选项页通过newTabSpec添加
3、选项页的内容可以通过R.id、或者new Intent()(需要声明相关的activity)或者createTabContent(需要实现TabHost.TabContentFactory)
4、tabHost.setOnTabChangedListener()这个方法比较常用。
- 初识选项卡 TabHost
- 选项卡TabHost
- [控件]TabHost选项卡
- 选项卡 TabHost
- 选项卡(TabHost)
- TabHost...选项卡
- android 选项卡TabHost
- android 选项卡TabHost
- TabHost 选项卡
- TabHost--选项卡案例
- android 选项卡(TabHost) 置底
- android 底部选项卡(TabHost)
- Android TabHost选项卡编程
- 选项卡TabHost的使用
- android TabHost选项卡示例
- android中tabhost选项卡
- android tabHost选项卡自定义
- Android TabHost 选项卡用法
- PC/UVa 110101/100 3n+1 问题(3n+1 Problem)
- 如何让DIV固定在页面的某个位置而不随着滚动条随意滚动 (转)
- 获取屏幕高度
- 在TextView上添加响应事件到另一个activity
- 为ListView中每一项里的ImageButton设置监听
- 初识选项卡 TabHost
- 将TabHost选项卡置底
- 设置TabHost中TabWidget的字体及图片样式
- 妙用TabHost----TabHost+RadioGroup组合使用
- android封装gallery
- android与webservice服务器交互
- ListView优化
- 看看你的编码乱在哪里
- XMPP——Smack状态,心情,头像更改