标签:android blog http io ar os 使用 java sp
TAB切换先上图,tab标题没有添加样式,因为setIndicator可以直接接收View,所以可以自己编辑样式:
也可以实现OnTabChangeListener监听tab的点击,改变tab点击后的样式风格

1、首先创建TabHost布局,TabActivity使用TabHost 为根目录,根目录必须使用ID:android:id="@android:id/tabhost"
窗体必须使用ID:android:id="@android:id/tabcontent"
Tab标题必须使用Id:android:id="@android:id/tabs"
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@android:id/tabhost"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<FrameLayout
android:layout_height="0dip"
android:layout_width="fill_parent"
android:layout_weight="1"
android:id="@android:id/tabcontent">
</FrameLayout>
<TabWidget android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs"></TabWidget>
</LinearLayout>
</TabHost>
2、创建Activity
package com.demo.tabactivity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
/**
* 这里实现继承tabActivity 实现tab页切换
* @author Administrator
*
*/
public class MainActivity extends TabActivity {
TabHost tab_host;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
//获得tabhost
tab_host = getTabHost();
//往tabhost添加tab,这里添加三个
createTabOne() ;
createTabTwo();
createTabThree();
}
/**
* 添加的tab页,实现方式也可以实现TabContentFactory接口来创建tab
*/
public void createTabOne() {
//创建tab窗体
Intent intent = new Intent(MainActivity.this,OneActivity.class);
//添加到tabost,其中setIndicator为设置tab标题,可以自己编辑Tab标题的样式内容,包括文字货图标
tab_host.addTab(tab_host.newTabSpec("第一页").setIndicator("第一页", null).setContent(intent));
}
/**
* 添加的tab页
*/
public void createTabTwo() {
Intent intent = new Intent(MainActivity.this,TwoActivity.class);
tab_host.addTab(tab_host.newTabSpec("第二页").setIndicator("第二页", null).setContent(intent));
}
/**
* 添加的tab页
*/
public void createTabThree() {
Intent intent = new Intent(MainActivity.this,ThreeActivity.class);
tab_host.addTab(tab_host.newTabSpec("第三页").setIndicator("第三页", null).setContent(intent));
}
}
其中OneActivity,TwoActivity,ThreeActivity为普通继承Activity的窗体,就不贴代码了
标签:android blog http io ar os 使用 java sp
原文地址:http://www.cnblogs.com/huxdiy/p/4077700.html