Android选项卡TabHost方式实现
1.布局XML:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabhost">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/bottomtip"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="@string/funPageBtn2"
android:gravity="center_horizontal|center_vertical"
android:layout_alignParentTop="true"
android:textColor="@android:color/white"
android:background="@android:color/black"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@android:id/tabs"
android:layout_below="@+id/bottomtip"
/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@android:color/black"
/>
</RelativeLayout> </TabHost>
布局效果理解:
2.Activity类实现
package com.test.appdemo1.actlearn; import com.test.appdemo1.R; import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec; @SuppressWarnings("deprecation")
public class TabOptTopAct extends TabActivity { private TabHost tabHost;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabtoplayout);
initTab();
} private void initTab() {
tabHost = getTabHost();
TabSpec tabSpec = null;
Intent intent = new Intent(this,MainActivity.class);
//第一个
tabSpec = tabHost.newTabSpec("tab1")
.setIndicator("首页",getResources().getDrawable(R.drawable.home))
.setContent(intent);
tabHost.addTab(tabSpec); //第二个
intent = new Intent(this,NextActivity.class);
tabSpec = tabHost.newTabSpec("tab2")
.setIndicator("邮件",getResources().getDrawable(R.drawable.mail))
.setContent(intent);
tabHost.addTab(tabSpec); //第三个
intent = new Intent(this,ServiceActDemo.class);
tabSpec = tabHost.newTabSpec("tab3")
.setIndicator("音乐",getResources().getDrawable(R.drawable.music))
.setContent(intent);
tabHost.addTab(tabSpec); //第四个
intent = new Intent(this,FrameLearnLayoutAct.class);
tabSpec = tabHost.newTabSpec("tab4")
.setIndicator("计算",getResources().getDrawable(R.drawable.calc))
.setContent(intent);
tabHost.addTab(tabSpec); tabHost.setCurrentTab(1);
} public void onBackPressed() {
super.onBackPressed();
finish();
}
}
最后说明:如果想把选项卡放到顶部只需修改布局文件中RelativeLayout里面的三个元素的位置
若有问题请大家指正.
程序运行效果如上图片所示.
Android选项卡TabHost方式实现的更多相关文章
- android 选项卡TabHost
选项卡主要有TabHost.TabWiget和 FramentLayout3个组件组成,用于实现一个多标签的用户界面,通过他可以将一个复杂的对话分隔成若干个标签页,实现对信息的分类显示和管理.使用给组 ...
- Android选项卡TabHost功能和用法
1.布局文件 <TabHost xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...
- Android 自学之选项卡TabHost
选项卡(TabHost)是一种非常实用的组件,TabHost可以很方便地在窗口上放置多个标签页,每个标签页相当于获得了一个与外部容器相同大小的组建摆放区域.通过这种方式,就可以在一个容器中放置更多组件 ...
- Android零基础入门第63节:过时但仍值得学习的选项卡TabHost
原文:Android零基础入门第63节:过时但仍值得学习的选项卡TabHost 由于前几天参加一个学习培训活动,几乎每天都要从早晨7点到晚上一两点,没有什么时间来分享,实在抱歉中间断更了几天.从今天开 ...
- android学习--TabHost选项卡组件
TabHost是一种非常有用的组件,TabHost能够非常方便地在窗体上放置多个标签页,每一个标签页获得了一个与外部容器同样大小的组件摆放区域.在手机系统的应用类似"未接电话".& ...
- Android 通过findViewById方式创建TabHost
package org.shuxiang.tabhostsample; import android.os.Bundle; import android.app.ActivityGroup; impo ...
- 12.Android之Tabhost组件学习
TabHost是整个Tab的容器,TabHost的实现有两种方式: 第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.各个Tab中的内容在布 ...
- Android:TabHost实现Tab切换
TabHost是整个Tab的容器,包含TabWidget和FrameLayout两个部分,TabWidget是每个Tab的表情,FrameLayout是Tab内容. 实现方式有两种: 1.继承TabA ...
- Android学习Tabhost、gallery、listview、imageswitcher
Tabhost控件又称分页控件,在很多的开发语言中都存在.它可以拥有多个标签页,每个标签页可以拥有不同的内容.android中,一个标签页可以放 一个view或者一个activity.TabHost是 ...
随机推荐
- [转]BluetoothDevice.getType()-一个常常被忽略了的函数。好用的不要不要的
自动安卓发布了4.0版本的蓝牙协议之后,越来越多的开发者收到了各种针对于BLE蓝牙的开发需求. 而且有很多时候还需要兼容以前的3.0版本,给大家的开发带来了困扰,笔者也遇到了这样的问题,偶然间发现了g ...
- Linux环境变量的设置和查看方法
Linux环境变量的设置和查看方法 1. 显示环境变量HOME [root@AY1404171530212980a0Z ~]# echo $HOME /root 2. ...
- Java在mysql插入数据的时候的乱码问题解决
今天在使用hibernate的时候,插入mysql的数据中的中文总是显示乱码,之前出现过类似的问题,但是没有太在意,今天又发生了.所以向彻底的解决一下. 参考的博文: http://www.cnblo ...
- Windows 2008 R2系统开机时如何不让Windows进行磁盘检测?
开始→运行,在运行对话框中键入“chkntfs /t:0”,即可将磁盘扫描等待时间设置为0, 如果要在计算机启动时忽略扫描某个分区,比如C盘,可以输入“chkntfs /x c:”命令:如果要恢复对C ...
- [转载]JQuery的Ajax跨域请求的解决方案
今天在项目中需要做远程数据加载并渲染页面,直到开发阶段才意识到ajax跨域请求的问题,隐约记得Jquery有提过一个ajax跨域请求的解决方式,于是即刻翻出Jquery的API出来研究,发现JQuer ...
- 【BZOJ 2453|bzoj 2120】 2453: 维护队列 (分块+二分)
2453: 维护队列 Description 你小时候玩过弹珠吗? 小朋友A有一些弹珠,A喜欢把它们排成队列,从左到右编号为1到N.为了整个队列鲜艳美观,小朋友想知道某一段连续弹珠中,不同颜色的弹珠有 ...
- TPS和QPS的区别
一.TPS:Transactions Per Second(每秒传输的事物处理个数),即服务器每秒处理的事务数.TPS包括一条消息入和一条消息出,加上一次用户数据库访问.(业务TPS = CAPS × ...
- [java]2015上海邀请赛 B Base64
题意: 给n和一个字符串(可以有空格) 求字符串编码n次后的字符串 编码方式:字符串的每个字符转化成ASCII码, ASCII码转化成8位2进制, 将二进制数分割成6位为一组的(不够的补0), ...
- BZOJ 4311 向量
shallot+向量集 混合版? 首先我们考虑每个向量的存在时间为[L,R] 那么我们知道任意一个区间在线段树上最多被分解成logn个区间 那么我们可以像shallot一样进行区间覆盖 注意到本题的查 ...
- 转XMLHelper
http://www.cnblogs.com/lixyvip/archive/2009/09/16/1567929.html using System; using System.Collection ...