TabHost

package com.example.text12_tabhost;import android.app.Activity;import android.os.Bundle;

import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.TabHost;import android.widget.TabHost.TabSpec;import android.widget.TextView;

public class MainActivity extends Activity {

private TabHost tabhost;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

tabhost=(TabHost) findViewById(R.id.tabhost);tabhost.setup()

;//找到Tabwidget和FrameLayout

//添加標(biāo)簽頁(yè)

TabSpec tab1 = tabhost.newTabSpec("tab1");

//指定標(biāo)簽

//tab1.setIndicator("首頁(yè)",getResources().getDrawable(R.drawable.i1));//指定標(biāo)簽的內(nèi)容tab1.setContent(R.id.line1);tabhost.addTab(tab1);

//添加標(biāo)簽頁(yè)TabSpec tab2 = tabhost.newTabSpec("tab2");

//指定標(biāo)簽tab2.setIndicator("首頁(yè)",getResources().getDrawable(R.drawable.i2));//指定標(biāo)簽的內(nèi)容tab2.setContent(R.id.line2);tabhost.addTab(tab2);//添加標(biāo)簽頁(yè)

TabSpec tab3 = tabhost.newTabSpec("tab3");//指定標(biāo)簽tab3.setIndicator("首頁(yè)",getResources().getDrawable(R.drawable.i3));//指定標(biāo)簽的內(nèi)容tab3.setContent(R.id.line3);tabhost.addTab(tab3);}

private View createView(String text){View view = View.inflate(this, R.layout.tab, null);TextView tv_title = (TextView) view.findViewById(R.id.tv_title);tv_title.setTag(tv_title);return view;

}

<TabHost?

xmlns:android="http://schemas.android.com/apk/res/android"

? ? ? ? android:layout_width="match_parent"

? ? ? ? android:layout_height="match_parent"

? ? ? ? android:id="@+id/tabhost"

? ? >

<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="match_parent"

? ? ? ? ? ? >

</TabWidget>

<FrameLayout

android:id="@android:id/tabcontent"

? ? ? ? ? ? android:layout_width="match_parent"

? ? ? ? ? ? android:layout_height="0dp"

? ? ? ? ? ? android:layout_weight="1"

? ? ? ? ? ? >

<!-- 首頁(yè) -->

<LinearLayout?

android:layout_width="match_parent"

? ? ? ? ? ? ? ? android:layout_height="match_parent"

? ? ? ? ? ? ? ? android:id="@+id/line1"

? ? ? ? ? ? ? ? >

<TextView?

android:layout_width="match_parent"

? ? ? ? ? ? ? ? ? ? android:layout_height="match_parent"

? ? ? ? ? ? ? ? ? ? android:text="首頁(yè)"

? ? ? ? ? ? ? ? ? ? android:textSize="30sp"

? ? ? ? ? ? ? ? ? ? android:gravity="center"

? ? ? ? ? ? ? ? ? ? />

</LinearLayout>

<LinearLayout?

android:layout_width="match_parent"

? ? ? ? ? ? ? ? android:layout_height="match_parent"

? ? ? ? ? ? ? ? android:id="@+id/line2"

? ? ? ? ? ? ? ? >

<TextView

android:layout_width="match_parent"

? ? ? ? ? ? ? ? ? ? android:layout_height="match_parent"

? ? ? ? ? ? ? ? ? ? android:text="第二頁(yè)"

? ? ? ? ? ? ? ? ? ? android:textSize="30sp"

? ? ? ? ? ? ? ? ? ? android:gravity="center"

? ? ? ? ? ? ? ? ? ? />

</LinearLayout>

<LinearLayout

android:layout_width="match_parent"

? ? ? ? ? ? ? ? android:layout_height="match_parent"

? ? ? ? ? ? ? ? android:id="@+id/line3"

? ? ? ? ? ? ? ? >

<TextView?

android:layout_width="match_parent"

? ? ? ? ? ? ? ? ? ? android:layout_height="match_parent"

? ? ? ? ? ? ? ? ? ? android:text="第三頁(yè)"

? ? ? ? ? ? ? ? ? ? android:textSize="30sp"

? ? ? ? ? ? ? ? ? ? android:gravity="center"

? ? ? ? ? ? ? ? ? ? />

</LinearLayout>

</FrameLayout>

</LinearLayout>

</TabHost>


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

? ? android:layout_width="match_parent"

? ? android:layout_height="match_parent"

? ? android:orientation="vertical"

? ? android:background="@drawable/bg" >

<TextView?

android:id="@+id/tv_title"

? ? ? ? android:layout_width="match_parent"

? ? ? ? android:layout_height="match_parent"

? ? ? ? android:gravity="center"

? ? ? ? android:text="首頁(yè)"

? ? ? ? android:textColor="@android:color/white"

? ? ? ? android:textSize="22sp"

? ? ? ? />

</LinearLayout>


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容