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是 ...
随机推荐
- flash链接需要后台调用时的插入flash方法
<!--<textarea id="syslink" style="display:none;">// 1:打宝塔 2:山寨玩法 3:跨服竞技 ...
- easyui 使特定tab处于选中状态
<div id="tabs" class="easyui-tabs"> <div title="Tab1" style=& ...
- POJ 1850 Code(组合数)
http://poj.org/problem?id=1850 题意 :给定字符串,系统是用字符串组成的,字符串是按字典序排的.编码系统有三条规则,1这些的单词的长度是由小到大的,2相同长度的按字母在字 ...
- poj 2265 Bee Maja
题目的意思很容易理解.就是找两个不同坐标的对应关系.下面的思路转自POJ的论坛 首先,记由1到2的方向记为2,1到3的方向记为3……1到7的方向记为7,他们分别是:(0,1),(-1,1),(-1,0 ...
- FileZilla Server 防火墙端口开启设置 windows 2008 win
入站规则 添加21端口, 程序FileZilla server.exe 出站规则 %SystemRoot%\System32\ftp.exe
- NSString的常用方法
创建一个新字符串并将其设置为 path 指定的文件的内容,使用字符编码enc,在error上返回错误 + (id)stringWithContentsOfURL:(NSURL *)url encodi ...
- 123. Best Time to Buy and Sell Stock III
题目: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...
- 编程之美:1.9高效率安排见面会 图的m着色问题 回溯法
原书问题,可以转换为图的m着色问题 ,下面该问题的代码 这里有参考ppt与code,免积分载 http://download.csdn.net/detail/u011467621/6341195 // ...
- java socket nio编程
上次写了一个socket的基本编程,但是有个问题,阻塞特别严重,于是小编便去找了nio学习了一下... public class TimeServer { public static void mai ...
- HTTPConnection与HTTPClient的区别
HttpClient是个很不错的开源框架,封装了访问http的请求头,参数,内容体,响应等等.HttpURLConnection是java的标准类,什么都没封装,用起来太原始,不方便.比如重访问的自定 ...