2012-07-23 91 views
1

首先, 我已經使用了生成的Activity使用標籤導航類型。我只是用它在Activity上自動生成Tab控件。其最新ADT。我認爲:(,, 現在我的問題是我怎麼到Tab內容android:我如何使用tabhost/tabwidget(通用tab)將不同的活動放在tabcontents上

其次使用Fragments其他Activity, 是否有任何其他的方式把另一個Activity內在Tab含量上,可以說,它的MainACtivity.class?....

規劃有3個Tab s的3個不同的Activity S,各自都包含1元tabActivity內容

真的需要你的幫助傢伙我已經用完了想法和來源:(:(... ... 一種新的android開發,所以要溫柔。 :)

+0

我已經對我的答案做了一些更改,嘿嘿一瞥。 – AkashG 2012-07-23 12:13:03

+0

本教程可能會幫助您http://http.wordpress.com/2013/12/18/how-to-use-tabwidget-with-fragments/ – Prachi 2013-12-23 11:36:29

回答

1

tab.xml:

<?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"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     > 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="60dp"/> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp"/> 
    </RelativeLayout> 

</TabHost> 

添加下面的代碼在你的activity.java文件:

通過android.app.TabActivity代替Activity

TabHost tabHost=getTabHost(); 
    TabHost.TabSpec spec; 
    Intent intent; 

    intent=new Intent().setClass(YourActivity.this, NewActivity.class); 
    spec=tabHost.newTabSpec("tab1").setIndicator("imageId").setContent(intent); 
    tabHost.addTab(spec); 

    intent=new Intent().setClass(YourActivity.this, New1Activity.class); 
    spec=tabHost.newTabSpec("tab2").setIndicator("imageId").setContent(intent); 
    tabHost.addTab(spec); 

    tabHost.setCurrentTab(0); 

拓展業務,以同樣的方式您可以在活動中添加儘可能多的選項卡。

+0

hmmm不是部件tabHost = getTabHost()假設爲findById (,,,)的東西得到tabhost?...因爲我得到了一個錯誤 – lemoncodes 2012-07-23 11:38:25

+0

我實現了這一點,它的運行fine.clean該項目,並再次運行它不會給你的error.if它這樣做比發佈錯誤 – AkashG 2012-07-23 11:56:49

+0

通過android.app.TabActivity而不是Activity來擴展該活動。那麼你不會得到錯誤。 – AkashG 2012-07-23 12:04:05

相關問題