mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTabHost; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class TabHostParentFragment extends Fragment { private FragmentTabHost tabHost; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { tabHost = new FragmentTabHost(getActivity()); tabHost.setup(getActivity(), getChildFragmentManager(), R.layout.my_parent_fragment); Bundle arg1 = new Bundle(); arg1.putInt("Arg for Frag1", 1); tabHost.addTab(tabHost.newTabSpec("Tab1").setIndicator("Frag Tab1"), NewsFragment.class, arg1); Bundle arg2 = new Bundle(); arg2.putInt("Arg for Frag2", 2); tabHost.addTab(tabHost.newTabSpec("Tab2").setIndicator("Frag Tab2"), MyNestedFragment2.class, arg2); return tabHost; }
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mTabHost = new FragmentTabHost(getActivity()); mTabHost.setup(getActivity(), getChildFragmentManager(), R.layout.my_parent_fragment);
private FragmentTabHost mTabHost; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mTabHost = new FragmentTabHost(getActivity()); mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.fragment1); mTabHost.addTab(mTabHost.newTabSpec("TabA").setIndicator("TabA"), TabA.class, null); mTabHost.addTab(mTabHost.newTabSpec("TabB").setIndicator("TabB"), TabB.class, null); return mTabHost; }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_connection, container, false); Bundle bundle = new Bundle(); bundle.putString(ActivityConstants.CONNECTION_KEY, connection.handle()); // Initialise the tab-host mTabHost = (FragmentTabHost) rootView.findViewById(android.R.id.tabhost); mTabHost.setup(getActivity(), getChildFragmentManager(), android.R.id.tabcontent); // Add a tab to the tabHost mTabHost.addTab(mTabHost.newTabSpec("History").setIndicator("History"), HistoryFragment.class, bundle); mTabHost.addTab(mTabHost.newTabSpec("Publish").setIndicator("Publish"), PublishFragment.class, bundle); mTabHost.addTab(mTabHost.newTabSpec("Subscribe").setIndicator("Subscribe"), SubscriptionFragment.class, bundle); return rootView; }
private void initViews() { tabhost = (FragmentTabHost) findViewById(R.id.main_tabHost); tabhost.setup(this,getSupportFragmentManager(),android.R.id.tabcontent); for (int i = 0; i < fragments.length; i++) { View view = getLayoutInflater().inflate(R.layout.item_tab,null); ImageView tabIcon = (ImageView) view.findViewById(R.id.item_tab_iv); TextView tabTitle = (TextView) view.findViewById(R.id.item_tab_tv); tabIcon.setImageResource(icons[i]); tabTitle.setText(resTitles[i]); tabhost.addTab(tabhost.newTabSpec(""+i).setIndicator(view),fragments[i],null); } }
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { FragmentTabHost tabHost = new FragmentTabHost(getActivity()); tabHost.setup(getActivity(), getChildFragmentManager(), android.R.id.content); tabHost.addTab(tabHost.newTabSpec("users").setIndicator("ПОЛЬЗОВАТЕЛИ"), SomeFragment.class, null); tabHost.addTab(tabHost.newTabSpec("posts").setIndicator("ПОСТЫ"), SomeFragment.class, null); tabHost.setOnTabChangedListener((TabHost.OnTabChangeListener) getActivity()); return tabHost; }
private FragmentTabHost mHost; public void changeFragment() { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); EntertainmentFragment enFragment = new EntertainmentFragment(); ft.replace(R.id.tabcontent, enFragment); ft.commit(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mHost.setup(this, getSupportFragmentManager(), R.id.tabcontent); mHost.addTab(mHost.newTabSpec("School") .setIndicator("School"), SchoolFragment.class, null); mHost.addTab(mHost.newTabSpec("Sport") .setIndicator("Sport"), SportsFragment.class, null); }
FragmentTabHost tabhost; void buildTabs() { tabhost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); tabhost.addTab(tabhost.newTabSpec("locations").setIndicator(getString(R.string.locations)), FragmentPreferencesLocations.class, null); tabhost.addTab(tabhost.newTabSpec("categories").setIndicator(getString(R.string.categories)),FragmentPreferencesCategories.class, null); }
private void initView() { layoutInflater = LayoutInflater.from(this); mTabHost = (FragmentTabHost) findViewById(R.id.id_tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.id_nav_table_content); int count = fragmentArray.length; for (int i = 0; i < count; i++) { TabHost.TabSpec tabSpec = mTabHost.newTabSpec(textViewArray[i]).setIndicator(getTabItemView(i)); mTabHost.addTab(tabSpec, fragmentArray[i], null); } }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override protected void init(Bundle savedInstanceState) { super.init(savedInstanceState); mPagerWrapper = (LinearLayout) findViewById(R.id.pager_wrapper); mTagHeight = 0; mPagerWrapper.setPadding(0, getActionBarSize() + mTagHeight, 0, 0); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); mTabHost.getTabWidget().setShowDividers(0); initTabs(); mTabHost.setCurrentTab(0); mTabHost.setOnTabChangedListener(this); }
private void initView(){ mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); // 关联TabHost mTabHost.setup(this,getSupportFragmentManager(),R.id.home_container); //注意,监听要设置在添加Tab之前 mTabHost.setOnTabChangedListener(this); //添加Tab for (int i=0;i<4;i++){ //生成TabSpec TabHost.TabSpec tabSpec = mTabHost.newTabSpec(mTabTitle[i]).setIndicator(DataGenerator.getTabView(this,i)); // 添加Tab 到TabHost,并绑定Fragment Bundle bundle = new Bundle(); bundle.putString("from","FragmentTabHost Tab"); mTabHost.addTab(tabSpec,mFragments[i].getClass(),bundle); } //去掉Tab 之间的分割线 mTabHost.getTabWidget().setDividerDrawable(null); // mTabHost.setCurrentTab(0); }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override protected void init(Bundle savedInstanceState) { super.init(savedInstanceState); mPagerWrapper = (LinearLayout) findViewById(R.id.pager_wrapper); mTagHeight = 0; mPagerWrapper.setPadding(0, getActionBarSize() + mTagHeight, 0, 0); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); mTabHost.getTabWidget().setShowDividers(0); initTabs(); mTabHost.setCurrentTab(0); mTabHost.setOnTabChangedListener(this); }
public class MainActivity extends FragmentActivity { private FragmentTabHost mTabHost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Tab 1",getResources().getDrawable(R.drawable.ic_launcher)), Home.class, null); mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Tab 2",getResources().getDrawable(R.drawable.ic_launcher)), CarPark.class, null); mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Tab 3", getResources().getDrawable(R.drawable.ic_launcher)), Shop.class, null); } }
public class Main2Activity extends AppCompatActivity { private FragmentTabHost mTabHost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent); mTabHost.addTab( mTabHost.newTabSpec("tab1").setIndicator("Tab 1", null), Tab1Fragment.class, null); mTabHost.addTab( mTabHost.newTabSpec("tab2").setIndicator("Tab 2", null), Tab2Fragment.class, null); mTabHost.addTab( mTabHost.newTabSpec("tab3").setIndicator("Tab 3", null), Tab3Fragment.class, null); }}
public class MainActivity extends Activity { FragmentTabHost mTabHost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTabHost = (FragmentTabHost) findViewById(R.id.tabhost); mTabHost.setup(this, getFragmentManager(), R.id.container); // Add each tab mTabHost.addTab(mTabHost.newTabSpec("first").setIndicator("first"), BlankFragment1.class, null); mTabHost.addTab(mTabHost.newTabSpec("second").setIndicator("second"), BlankFragment2.class, null); mTabHost.postDelayed(new Runnable() { @Override public void run() { mTabHost.setCurrentTabByTag("second"); } }, 5000); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mTabHost.setup(mContext, getSupportFragmentManager(), R.id.realtabcontent); mTabHost.addTab(getTabSpec("tab1"), ColorFragment.class, getArgs(0)); mTabHost.addTab(getTabSpec("tab2"), ColorFragment.class, getArgs(1)); mTabHost.addTab(getTabSpec("tab3"), CustomViewFragment.class, null); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle("统计UApp"); setBackVisibily(); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"), FragmentSimple.class, null); mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"), FragmentContacts.class, null); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fabric.with(this, new Crashlytics()); setContentView(R.layout.activity_recording); tabHost = (FragmentTabHost)findViewById(R.id.tabhost); tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); this.addTab(ReadingFragment.class, getString(R.string.title_text)); this.addTab(RecordGraphFragment.class, getString(R.string.realtime_graph)); SharedPreferences sharedPref = getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE); Integer tabIndex = sharedPref.getInt(getString(R.string.recording_tab_index), 0); tabHost.setCurrentTab(tabIndex); }