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是 ...
随机推荐
- 在Oracle SQL Developer中创建新连接
步骤: 1.如下图 2.点击“测试”,如果左下角的状态出现“成功”,说明OK
- POJ3297+map字符串处理
简单的字符串处理题. 要注意细节! 附数据两组: ABCC abc ae AAA abc AAAA abc A a B a C a /* */ #include<stdio.h> #inc ...
- hdu 2509 Be the Winner 博弈论
博弈论水题!!! 代码如下: #include<stdio.h> #include<iostream> using namespace std; int main(){ int ...
- android 动态改变listview的内容
本文模拟:点击一个按钮,为已有的listview添加一行数据 <?xml version="1.0" encoding="utf-8"?> < ...
- IDEA 创建maven-web project失败一例
今天使用IDEA创建WEB-APP总是失败,经排查原来是MAVEN环境没配置好!!! 配置: M2_HOME--->maven解压目录 path---->%M2_HOME%\bin\
- 使用eclipse远程调试Tomcat的方法
tomcat是一种非常常见的java web应用服务器,有时候服务器可能并不是部署在本地,而是部署在远程其他的机器上,我们用eclispe该如何进行debug调试呢? 1. 在eclispe中新建we ...
- SaaS系列介绍之五: 我国SaaS市场分析
1 我国SaaS市场现状 我国SaaS从ASP年代发展到今天,也有不少时间了.我国是个十几亿人的大国,国情复杂,各地贫富不均,发展不平衡.信息系统建设也是各树一帜,各地为王.特别是占有大量用户的中小企 ...
- open/write/read
C语言中open函数 作用:打开和创建文件. 简述: 1 2 3 4 #include <fcntl.h> int open(const char *pathname, int flags ...
- C动态内存分配(C与指针实例)
主要初步介绍malloc.free.calloc.realloc的基本.日后会有更详细的内容. malloc.free分别用于动态内存分配和释放. malloc会从内存池里提取一块合适的内存(连续的) ...
- ARM7ldr指令与ldr伪指令
ldr伪指令的第二个操作数之前有个=,意思是第一个操作书 = 第二个操作数,相当明了 核心就在于对于用.word指令在.text段里另外定义一段内存,用ldr r0,[pc + x(可以算出.text ...