自己定义的Tabhost

<?xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"android:layout_height="fill_parent"

android:orientation="vertical">

<TabHostandroid:id="@+id/view_tab_host"android:layout_width="fill_parent"

android:layout_height="fill_parent">

<LinearLayoutandroid:layout_width="fill_parent"

android:layout_height="fill_parent"android:gravity="center"

android:orientation="vertical">

<FrameLayoutandroid: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>

<TabWidgetandroid:id="@android:id/tabs"

android:layout_width="fill_parent"android:layout_height="52dip"

android:layout_weight="0">

</TabWidget>

</LinearLayout>

</TabHost>

</LinearLayout>

packagecn.fn;

importandroid.app.ActivityGroup;

importandroid.content.Intent;

importandroid.os.Bundle;

importandroid.view.LayoutInflater;

importandroid.widget.ImageView;

importandroid.widget.LinearLayout;

importandroid.widget.TabHost;

importandroid.widget.TabWidget;

importandroid.widget.TextView;

importandroid.widget.TabHost.TabSpec;

publicclassTabHostActivityextendsActivityGroup{

privateTabHosttabHost;

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

//加载TabSpec

tabHost=(TabHost)findViewById(R.id.view_tab_host);

tabHost.setup(getLocalActivityManager());

TabWidgettabWidget=tabHost.getTabWidget();

tabHost.addTab(tabHost.newTabSpec("text1").setIndicator("选项卡1")

.setContent(

newIntent(TabHostActivity.this,Text1Activity.class)));

tabHost.addTab(tabHost.newTabSpec("text2").setIndicator("选项卡2")

.setContent(

newIntent(TabHostActivity.this,Text1Activity.class)));

//设置标签栏背景图片

tabHost.setCurrentTab(1);

tabWidget.setBackgroundResource(R.drawable.bg);

}

}

相关推荐