默认情况下,tabhost的行为似乎会自动选择第一个选项卡并显示其内容。问题是,我想设置它的默认页面。 (这意味着,默认情况下,tabhost未被选中,并显示一些主页内容,(不是tabhost的内容))。如何实现这样的功能?感谢。
主要活动
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 :(得分:0)
我修好了。 添加一个标签并设置它的可见性是View.gone