TabHost页卡
2015-10-20 19:03
267 查看
TabHost 是一种布局,继承于FrameLayout 的;
由三部分组成:tabcontent+ title+tab; tabcontent 其实就是一个activity,由一层FrameLayout 包裹
TabHost /TabWidget//FrameLayout id为固定以下系统id
android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="@drawable/button_click_selector" > </TabWidget>
由三部分组成:tabcontent+ title+tab; tabcontent 其实就是一个activity,由一层FrameLayout 包裹
TabHost /TabWidget//FrameLayout id为固定以下系统id
<?xml version="1.0" encoding="utf-8"?>
<!-- 外面那一层布局 --> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" <span style="color:#990000;">android:id="@android:id/tabhost"</span> android:layout_width="match_parent" android:layout_height="match_parent" >
<!-- 页卡tabs -->
<pre name="code" class="html"><!-- 属性visible=“gone”原本的tab消失且不占空间 --><TabWidget
android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="@drawable/button_click_selector" > </TabWidget>
<!-- 内容区域 --> <FrameLayout <span style="color:#990000;">android:id="@android:id/tabcontent"</span> android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@android:id/tabs" > </FrameLayout> </TabHost>
TabHost tabHost = getTabHost(); //页卡标签,自定义页卡时,监听自定义控件时,用mTabHost.setCurrentTabByTag("tab1");将两者联系起来 TabSpec tabspec1 = tabHost.newTabSpec("tab1"); tabspec1.setIndicator("main");//设置tab页卡的名字 tabspec1.setContent(new Intent(this, DefinedActivity.class));//响应事件,启动activity TabSpec tabspec2 = tabHost.newTabSpec("tab2"); tabspec2.setIndicator("first"); tabspec2.setContent(new Intent(this, ViewPagerActivity.class)); TabSpec tabspec3 = tabHost.newTabSpec("tab3"); tabspec3.setIndicator("last"); tabspec3.setContent(new Intent(this, SimpleAdapterActivity.class)); tabHost.addTab(tabspec1); tabHost.addTab(tabspec2); tabHost.addTab(tabspec3);
相关文章推荐
- double以及float数据类型
- JavaWeb学习路线简介
- 产生二维码的Android例子
- HTTP必知必会(转)
- Java中特殊字符处理(转义字符)
- eclipse自动补全设置
- 与任正非的一次花园谈话
- 二叉树的友好实现(转)
- 关于在代码中设置TextView的textSize
- My_Graph2 DFS BFS
- android 限制输入字符数!看清楚:是限制字符数,不是字数!中英混排?就算emoji也不怕啦!
- struts1.x mvc简单例程
- struts1.x mvc简单例程
- Docker在windows下无法开启伪终端解决方法
- spring mvc 如何传递集合参数(list,数组)
- 【Maven】maven配置默认使用的JDK版本
- smarty显示二维数组的数据
- 数控分频器的设计
- 从0开始学Java——JSP和Servlet——jsp转servlet出错的三个典型场景
- const和static const还有static区别