0

tabhost的行爲默認情況下會自動選擇第一個選項卡並顯示它的內容。問題是,我想設置它的默認頁面。 (這意味着,默認情況下,tabhost未被選中,並顯示一些主頁內容(不是tabhost的內容))。如何實現這樣的功能?謝謝。如何在android中設置標籤主機的默認頁面?

主要活動

public class LandingPage extends FragmentActivity { 
    public FragmentTabHost tabHost; 
    public Resources res; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.landing_page); 
     res = getResources(); 
     tabHost = (FragmentTabHost) findViewById(R.id.tabhost); 
     tabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent); 
     tabHost.addTab(tabHost.newTabSpec("About").setIndicator("",res.getDrawable(R.drawable.btn_about)),About.class, null); 
     tabHost.addTab(tabHost.newTabSpec("Selfie").setIndicator("",res.getDrawable(R.drawable.btn_selfie)),About.class, null); 
     tabHost.addTab(tabHost.newTabSpec("Gallery").setIndicator("",res.getDrawable(R.drawable.btn_gallery)),About.class, null); 
     tabHost.addTab(tabHost.newTabSpec("LeaderBoard").setIndicator("",res.getDrawable(R.drawable.btn_board)),About.class, null); 
     tabHost.addTab(tabHost.newTabSpec("Events").setIndicator("",res.getDrawable(R.drawable.btn_events)),Events.class, null); 
    } 
} 

XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <android.support.v4.app.FragmentTabHost 
     android:id="@+id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:orientation="horizontal" 
     android:background="@drawable/share_navigation_bar_bg" /> 

    <FrameLayout 
     android:id="@+id/tabcontent" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 

</LinearLayout> 

回答

0

我固定它。 添加一個選項卡並將其可見性設置爲View.gone