2011-09-09 14 views

回答

3
<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" 
     android:id="@+id/header"> 
     <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:text="woopra" android:textColor="#ffffff" android:textSize="36sp" 
      android:textStyle="bold"/> 
    </LinearLayout>  
    <FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> 
     <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:visibility="gone"/>    
     <LinearLayout android:layout_width="fill_parent" android:layout_height="64dip"> 
      <Button android:layout_height="fill_parent" android:layout_width="0dip" 
       android:layout_weight="1.0" android:id="@+id/dashboard_tab" 
       android:onClick="tabHandler" android:text="Dashboard"/> 
      <Button android:layout_height="fill_parent" android:layout_width="0dip" 
       android:layout_weight="1.0" android:id="@+id/visitors_tab" 
       android:onClick="tabHandler" android:text="Vistors"/> 
      <Button android:layout_height="fill_parent" android:layout_width="0dip" 
       android:layout_weight="1.0" android:id="@+id/chat_tab" android:onClick="tabHandler" 
       android:text="Chat"/> 
      <Button android:layout_height="fill_parent" android:layout_width="0dip" 
       android:layout_weight="1.0" android:id="@+id/reports_tab" 
       android:onClick="tabHandler" android:text="Reports"/> 
     </LinearLayout> 
    </FrameLayout> 
    <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0dip" 
       android:layout_weight="1.0"/> 
</LinearLayout> 

這裏id爲 'tabcontent' 的FrameLayout裏是我們的選項卡的內容去。無論您選擇哪個標籤,您在該framwlayout之外放置的內容都將位於標籤頁活動中。

如果你看看xml的頂部,你可以看到一個id爲'header'的線性佈局。這是我製作的標題佈局,它總是在標籤佈局中可見。您也可以通過將按鈕而不是像iive完成的文本視圖來創建工具欄。

+0

感謝您的代碼!它幫助我解決了我的問題。 – MduSenthil

+0

設置此答案。它將幫助未來的用戶甚至未來的參考。 – blessenm

0

只要把你的工具欄放在佈局中,有什麼問題?

+0

如何將該工具欄定義爲Tabactivity的佈局? – MduSenthil

+0

製作一個普通的佈局,並設置tabhost.to的ID爲@android:id/tabs。其實,它應該有默認的id。 –

+0

我有四個選項卡和四個活動以完善的方式。但是,除此之外,我需要在每個選項卡關聯的每個活動的頂部都有一個工具欄。 – MduSenthil

相關問題