2012-02-21 22 views
1

我在tabbar中有四個選項卡。無論何時啓動我的應用程序,我需要運行一個tabbar的所有選項卡(四個),因爲所有選項卡都包含應在每次啓動應用程序時加載的webviews。但第一個標籤應該突出顯示。我已經使用了如何在Android中同時加載標籤欄的所有選項卡

setCurrentTab(0); 

加載第一個選項卡,但是iam無法加載其餘選項卡而不點擊。

回答

0

爲此,請先創建一個xml文件。示例文件如下所示。

<?xml version="1.0" encoding="utf-8"?> 
<TabHost android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:id="@android:id/tabhost" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:background="@drawable/background"> 
    <TabWidget android:layout_width="fill_parent" android:id="@android:id/tabs" 
     android:layout_height="wrap_content" /> 
    <FrameLayout android:layout_width="fill_parent" android:id="@android:id/tabcontent" 
     android:layout_gravity="bottom" android:paddingTop="70dp" 
     android:layout_height="match_parent"> 

    <ScrollView android:layout_height="fill_parent" android:id="@+id/viewTab1" 
     android:layout_width="match_parent"> 
     <!-- Your view you want --> 

    </ScrollView> 
    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:id="@+id/viewTab2"> 
     <!-- Your view you want --> 

    </LinearLayout> 

    <!-- Add as many view you want with unique id --> 
</FrameLayout> 

每個佈局將把獨特的佈局。

在主要活動中使用下列

TabHost tabHost = getTabHost(); 
TabSpec spec1 = tabHost.newTabSpec("FirstTabView"); 
TabSpec spec2 = tabHost.newTabSpec("SecondTabView"); 

spec1.setContent(R.id.viewTab1); 
spec1.setIndicator("First Tab"); 

spec2.setIndicator("Second Tab"); 
spec2.setContent(R.id.viewTab2); 

tabHost.addTab(spec1); 
tabHost.addTab(spec2); 

tabHost.setup(); 

您可以根據需要添加儘可能多的標籤。這一切將在同一時間初始化。

我希望這可以幫助你:)

相關問題