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是 ...
随机推荐
- 839. Optimal Marks - SPOJ
You are given an undirected graph G(V, E). Each vertex has a mark which is an integer from the range ...
- Linux环境变量的设置和查看方法
Linux环境变量的设置和查看方法 1. 显示环境变量HOME [root@AY1404171530212980a0Z ~]# echo $HOME /root 2. ...
- [转载]vs2012中使用Spring.NET报错:Spring.Context.Support.ContextRegistry 的类型初始值设定项引发异常
学习使用Spring.NET中的时候,写了一个Demo,在运行时报了一个错误:Spring.Context.Support.ContextRegistry 的类型初始值设定项引发异常. 重新整理思绪, ...
- PAT-乙级-1006. 换个格式输出整数 (15)
1006. 换个格式输出整数 (15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 让我们用字母B来表示“百” ...
- PHP截取字符串,获取长度,获取字符位置的函数
strstr(string,string) = strchr(,) //从前面第一次出现某个字符串的地方截取到最后strrchr(string,string) //从某个字符串从最后出现的位置截取到结 ...
- Kerbose
http://blog.csdn.net/wulantian/article/details/42418231
- 阿里云,CentOS下yum安装mysql,jdk,tomcat
首先说明,服务器是阿里云的,centos6.3_64位安全加固版.首先需要登陆进来,使用的是putty,因为最初的时候,Xshell登陆会被拒绝. 0. 创建个人文件夹 # 使用 yum 安装tomc ...
- POJ2993——Help Me with the Game(字符串处理+排序)
Help Me with the Game DescriptionYour task is to read a picture of a chessboard position and print i ...
- 【开源推荐】AllJoyn:打造全球物联网的通用开源框架
摘要:随着智能设备的发展,物联网逐渐进入了人们的生活.据预测,未来几乎一切东西(超过500亿台设备)都可以互联.高通公司发布了开源项目AllJoyn,这是一个能够使连接设备间进行互操作的通用软件框架和 ...
- Java面试题-多线程
1. java中有几种方法可以实现一个线程? 多线程有两种实现方法,分别是继承Thread类与实现Runnable接口. 这两种方法的区别是,如果你的类已经继承了其它的类,那么你只能选择实现Runna ...