自己定义的Tabhost

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">

<TabHost android:id="@+id/view_tab_host" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center"
android:orientation="vertical">

<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_gravity="center_vertical" android:layout_weight="1"
android:gravity="center_vertical">
</FrameLayout>

<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="52dip"
android:layout_weight="0">
</TabWidget>
</LinearLayout>
</TabHost>

</LinearLayout>


package cn.fn;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;

public class TabHostActivity extends ActivityGroup {
private TabHost tabHost;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 加载TabSpec
tabHost = (TabHost) findViewById(R.id.view_tab_host);
tabHost.setup(getLocalActivityManager());
TabWidget tabWidget = tabHost.getTabWidget();


tabHost.addTab(tabHost.newTabSpec("text1").setIndicator("选项卡1")
.setContent(
new Intent(TabHostActivity.this, Text1Activity.class)));

tabHost.addTab(tabHost.newTabSpec("text2").setIndicator("选项卡2")
.setContent(
new Intent(TabHostActivity.this, Text1Activity.class)));

// 设置标签栏背景图片
tabHost.setCurrentTab(1);
tabWidget.setBackgroundResource(R.drawable.bg);
}
}

你可能感兴趣的:(android,自定义Tabhost)