Tabhost最纯净的实现方式
有时候常常使用别人用Tabhost+其他的实现demo。单纯利用Tabhost该怎样使用呢?
以下看样例:
public class MainActivity extends TabActivity {
public TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 获取对象
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("index").setIndicator("实时新闻")
.setContent(new Intent(this, IndexActivity.class)));
tabHost.addTab(tabHost.newTabSpec("center").setIndicator("我的空间")
.setContent(new Intent(this, MiddleActivity.class)));
tabHost.addTab(tabHost.newTabSpec("self").setIndicator("设置")
.setContent(new Intent(this, LastActivity.class)));
// 指定的当前的tab
// 通过索引指定 索引从0開始
// 即一開始要显示的是哪一页
tabHost.setCurrentTab(0); // 从零開始
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
二、效果图
(2)Tabhost选项卡置于底部的样例
採用LinearLayout布局。设置Weight属性就能够将选项卡位于底部
1、xml布局文件
<? xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:orientation="vertical" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0" >
</FrameLayout> <TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
</LinearLayout> </TabHost>
2、MainActivity
public class MainActivity extends ActivityGroup
{
private TabHost mTabHost; @Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initTabs();
} private void initTabs()
{
mTabHost = (TabHost) findViewById(R.id.tabhost);
mTabHost.setup(this.getLocalActivityManager()); Intent intent = new Intent(this, HomepageActivity.class);
mTabHost.addTab(mTabHost.newTabSpec("Tab1")
.setIndicator(getString(R.string.homepage_indicator), getResources().getDrawable(R.drawable.homepage_indicator_selector))
.setContent(intent)); intent = new Intent(this, BillboardActivity.class);
mTabHost.addTab(mTabHost.newTabSpec("Tab2")
.setIndicator(getString(R.string.billboard_indicator), getResources().getDrawable(R.drawable.billboard_indicator_selector))
.setContent(intent)); intent = new Intent(this, MyLotteryActivity.class);
mTabHost.addTab(mTabHost.newTabSpec("Tab3")
.setIndicator(getString(R.string.mylottery_indicator), getResources().getDrawable(R.drawable.mylottery_indicator_selector))
.setContent(intent)); intent = new Intent(this, MoreActivity.class);
mTabHost.addTab(mTabHost.newTabSpec("Tab4")
.setIndicator(getString(R.string.more_indicator), getResources().getDrawable(R.drawable.more_indicator_selector))
.setContent(intent));
}
}
3、效果图
Tabhost最纯净的实现方式的更多相关文章
- Android 常用UI控件之TabHost(1)TabHost的两种布局方式
TabHost是Android中的tab组件. TabHost布局文件的基本结构 TabHost下有个layout,这个layout中有TabWidget与FrameLayout.TabWidget是 ...
- TabHost创建的2种方式
一.如果是自定义TabHost步骤如下 1.必须给tabHost跟标签设置一个android:id="@android:id/tabhost"> 2.必须创建TabWidge ...
- Android工作学习第5天之TabHost实现菜单栏底部显示
TabHost是一个装载选项卡窗口的容器,实现分模块显示的效果.像新浪微博客户端.微信客户端都是使用tabehost组件来开发的. TabHost的组成: |---TabWidget:实现标签栏,可供 ...
- Android用户界面开发:TabHost
TabHost是整个Tab的容器,包括两部分,TabWidget和FrameLayout.TabWidget就是每个tab的标签,FrameLayout则是tab内容.TabHost的二种实现方式:第 ...
- TabHost的初步使用
本文主要参考自:http://blog.csdn.net/wulianghuan/article/details/8588947 (里面有TabHost第二种定义的方式,继承TabActivity) ...
- 相当郁闷的问题,TabHost选项卡标签图标始终不出现?
在学习Android TabHost布局过程中,很多教程告诉我,这样来显示选项卡标签的图标和文字: TapSpec spec1 = tabHost.newTabSpec("tab 1&quo ...
- tabhost实现android菜单切换
做APP项目已经有半个月了.慢慢地熟悉了这个开发环境和开发套路. 虽然是摸着石头过河.但也渐渐看到了水的深度! 作为一个电商项目APP,势必会涉及究竟部菜单条的功能.自己实现这个功能的过程是崎岖的,最 ...
- Yii Framework2.0开发教程(1)配置环境及第一个应用HelloWorld
准备工作: 我用的开发环境是windows下的apache+mysql+php 编辑器不知道该用哪个好.临时用dreamweaver吧 我自己的http://localhost/相应的根文件夹是E:/ ...
- 同步博客到cnblogs平台
缘由 最最开始在csdn写博客,广告太多,平台暗调资源积分,退:后来使用githubpage+jeklly搭建静态博客,感觉不错,回归到安静的敲打环境.emmmm,由于是静态博客项目,虽能最大化自定义 ...
随机推荐
- 机器翻译评测——BLEU改进后的NIST算法
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/7765345.html 上一节介绍了BLEU算的缺陷.NIS ...
- asp.net 自定义的模板方法接口通用类型
本来想写这个帖子已经很久了,但是公司事情多,做着做着就忘记了.公司因为需要做接口,而且用的还是asp.net的老框架,使用Handler来做,没得办法,自己照着MVC写了一个通过的接口操作模板. 上送 ...
- Scrum Meeting Alpha - 3
Scrum Meeting Alpha - 3 NewTeam 2017/10/27 地点:新主楼F座二楼 任务反馈 团队成员 完成任务 计划任务 安万贺 找到了几个开源项目,参考了API的包装方式, ...
- SqlServer 数据库附加问题:不是主数据库文件
一.前言 今天公司要切换数据库服务器,数据库文件大于2G,结果再附加到另一服务器的数据库里面,就产生了一个问题.如下: 标题:Microsoft SQL Server Management Studi ...
- c# RSA加密和解密
"); Console.WriteLine(encodeString); string decode = MyRSA.Decrypt(encode ...
- ARM1
CPU有取指周期,译码周期,执行周期包括的器件有程序计数器(CP),指令cache,数据总线,指令寄存器(IR),数据地址寄存器(AR),指令译码器,时序发生器操作控制器,控制总线,数据缓冲寄存器(D ...
- Python 简单的天气预报
轻巧的树莓派一直是大家的热爱,在上面开发一些小东西让我们很有成就感,而在linux下,python能使麻烦的操作变得简单,而树莓派功耗还很低,相结合,完美! 1,直接进入正题,一般在linux或树莓派 ...
- [转]结合HierarchyViewer和APK文件反编译获得APP元素id值
背景: 最近在使用Robotium进行Android自动化测试.遇到了一个问题:我需要获得一个View的id(int型数值).此前我在http://maider.blog.sohu.com/25544 ...
- Redis使用说明详解
原博主地址:http://www.cnblogs.com/wangyuyu/p/3786236.html Redis使用详细教程 一.Redis基础部分: 1.redis介绍与安装比mysql快10倍 ...
- 01_Python简介
Python 简介 *为什么学习python http://bbs.fishc.com/thread-35584-1-1.html Python 特点 易于学习:Python有相对较少的关键字,结构简 ...