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,由于是静态博客项目,虽能最大化自定义 ...
随机推荐
- HTML5与phonegap接口对比
HTML5与phonegap接口对比 接口 HTML5 phonegap 差异 地理定位 geolocation 单次定位: navigator.geolocation.getCurrentPosit ...
- Python爬虫小实践:寻找失踪人口,爬取失踪儿童信息并写成csv文件,方便存入数据库
前两天有人私信我,让我爬这个网站,http://bbs.baobeihuijia.com/forum-191-1.html上的失踪儿童信息,准备根据失踪儿童的失踪时的地理位置来更好的寻找失踪儿童,这种 ...
- Linux下打造全方位立体监控系统
前言 本文主要介绍如何使用Grafana和Prometheus以及node_exporter对Linux服务器性能进行监控.下面两张图分别是两台服务器: 服务器A 服务器B 概述 Prometheus ...
- freeMarker遍历map的正确方式
假设selectDateModel 是我们后台返回的map<String, String>; <#list selectDateModel?keys as key> <o ...
- c#正则表达式应用实例
两种使用方法: 1.在文本输入框后加入正则表达式验证控件Regularexpression_r_rValidator.此种方法适用于WebForm中.在Validationexpression_r_r ...
- 基础教程:视图中的ASP.NET Core 2.0 MVC依赖注入
问题 如何在ASP.NET Core MVC Views中注入和使用服务. 解 更新 启动 类来为MVC添加服务和中间件. 添加一项服务 添加一个Controller,返回 ViewResult. 添 ...
- 利用bootstrap写的一点本地(localStorage)储存
摘要: H5本地存储 在以前,我们想要存储一些数据,并且只是在前端使用,服务端并不会使用,我们只能存在cookie里,但是cookie会跟随请求头在客户端和服务端之间来回传递,而且cookie还有一些 ...
- P3092 [USACO13NOV]没有找零No Change
题目描述 Farmer John is at the market to purchase supplies for his farm. He has in his pocket K coins (1 ...
- Python随笔------初探
今年的双十一刚刚才过去,大多数人主要就是抢购商品,可能他们现在已经收到了他们夜以继日抢购的商品.然而对于我们做技术的,特别是做互联网技术的,我相信肯定都被双十一那天的许多技术震撼到了吧.云计算.分压式 ...
- 如何在README.md文件中添加图片
原文链接:https://www.cnblogs.com/hongmaju/p/6873720.html 1.在github上的仓库建立一个存放图片的文件夹,文件夹名字随意.如:img-folder ...