package com.example.lenovo.learnandroiddesign; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTabHost; import android.widget.TabHost; public class FragmentNestingTabsActivity extends FragmentActivity { FragmentTabHost mTabHost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { setContentView(R.layout.activity_fragment_nesting_tabs); mTabHost=(FragmentTabHost) this.findViewById(R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.realcontent); mTabHost.addTab(mTabHost.newTabSpec("menus").setIndicator("Menus"), TestFragment.class, null); mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"), TestFragment.class, null); mTabHost.addTab(mTabHost.newTabSpec("stack").setIndicator("Stack"), TestFragment.class, null); mTabHost.addTab(mTabHost.newTabSpec("tabs").setIndicator("Tabs"), TestFragment.class, null); }catch (Exception ex) { ex.printStackTrace(); } }}
需要严重注意的是:
1.必须在fragmenthost的下级标签定义,id为tabcontent的framelayout的标签
<android.support.v4.app.FragmentTabHost android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tabhost"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="0" /> </android.support.v4.app.FragmentTabHost>
根据FragmentTabhost新建导航条
最新推荐文章于 2019-06-11 16:16:24 发布