`
rayln
  • 浏览: 414898 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

TabHost的基本使用方法

 
阅读更多
非常简单的例子说明一个TabHost的使用

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
	<TabHost
	    android:id="@android:id/tabhost"
	    android:layout_width="match_parent"
	    android:layout_height="match_parent"
	    android:layout_alignParentBottom="true"
	    android:layout_alignParentLeft="true" >
	
	    <LinearLayout
	        android:layout_width="match_parent"
	        android:layout_height="match_parent"
	        android:orientation="vertical" >
	
	        <TabWidget
	            android:id="@android:id/tabs"
	            android:layout_width="match_parent"
	            android:layout_height="wrap_content" >
	        </TabWidget>
	
	        <FrameLayout
	            android:id="@android:id/tabcontent"
	            android:layout_width="match_parent"
	            android:layout_height="match_parent" >
	
	            <LinearLayout
	                android:id="@+id/tab1"
	                android:layout_width="match_parent"
	                android:layout_height="match_parent" >
	            </LinearLayout>
	
	            <LinearLayout
	                android:id="@+id/tab2"
	                android:layout_width="match_parent"
	                android:layout_height="match_parent" >
	            </LinearLayout>
	
	            <LinearLayout
	                android:id="@+id/tab3"
	                android:layout_width="match_parent"
	                android:layout_height="match_parent" >
	            </LinearLayout>
	        </FrameLayout>
	    </LinearLayout>
	</TabHost>

</RelativeLayout>


package com.msg.vo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		createTabs();
	}
	
	private void createTabs(){
		TabHost th = (TabHost)findViewById(android.R.id.tabhost);
		th.setup();
		TabSpec ts1 = th.newTabSpec("1");
		ts1.setIndicator("tab1");
		ts1.setContent(R.id.tab1);
		
		TabSpec ts2 = th.newTabSpec("2");
		ts2.setIndicator("tab2");
		ts2.setContent(R.id.tab2);
		
		TabSpec ts3 = th.newTabSpec("3");
		ts3.setIndicator("tab3");
		ts3.setContent(R.id.tab3);
		
		th.addTab(ts1);
		th.addTab(ts2);
		th.addTab(ts3);
	}

}
分享到:
评论

相关推荐

    详解Android应用中使用TabHost组件进行布局的基本方法

    getHost()获取前提 : 设置了该id之后, 在Activity界面可以使用 getHost(), 获取这个TabHost 视图对象; 示例 : 代码如下: &lt;tabhost android:id=”@android:id/tabhost” android:layout_height=”match_parent”

    FragmentTabHost的基本使用

    FragmentTabHost常见使用方法,http://blog.csdn.net/yalinfendou博客中有详细介绍……

    疯狂Android讲义源码

     8.3.5 使用特定方法操作SQLite  数据库 327  8.3.6 事务 329  8.3.7 SQLiteOpenHelper类 330  8.4 手势(Gesture) 335  8.4.1 手势检测 335  8.4.2 增加手势 342  8.4.3 识别用户的手势 346  8.5 自动...

    疯狂Android讲义.part2

    8.3.5 使用特定方法操作SQLite 数据库 327 8.3.6 事务 329 8.3.7 SQLiteOpenHelper类 330 8.4 手势(Gesture) 335 8.4.1 手势检测 335 8.4.2 增加手势 342 8.4.3 识别用户的手势 346 8.5 自动朗读(TTS) 347 8.6 ...

    疯狂Android讲义.part1

    8.3.5 使用特定方法操作SQLite 数据库 327 8.3.6 事务 329 8.3.7 SQLiteOpenHelper类 330 8.4 手势(Gesture) 335 8.4.1 手势检测 335 8.4.2 增加手势 342 8.4.3 识别用户的手势 346 8.5 自动朗读(TTS) 347 8.6 ...

    android开发资料大全

    基本控件及基本动画效果dem 2011android面试题目及其答案大全.rar Android面试题集锦 (陆续更新)(最新2012-6-18) 【eoeAndroid Android相关的面试题最强汇总】 ZTE—adroid笔试题附答案版 iceskysl: 说说我招聘...

    Android初学者必须知道的10个技术

    如果你是往Android开发路上走,那么以下的10个技术...使用方法: private void initBGALayout() { // 为BGARefreshLayout 设置代理 bgaRefreshLayout.setDelegate(this); // 设置下拉刷新和上拉加载更多的风格 参

Global site tag (gtag.js) - Google Analytics