private void initEvent() { mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { mViewPager.setCurrentItem(mTabHost.getCurrentTab()); } }); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { mTabHost.setCurrentTab(position); } @Override public void onPageScrollStateChanged(int state) { } }); }
@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; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_activty); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); } FragmentTabHost tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); tabHost.setup(this, getSupportFragmentManager(), R.id.real_content); Bundle bundle = new Bundle(); bundle.putString("mode", SEARCH_MODE_TOPIC); bundle.putInt("fid", getIntent().getIntExtra("fid", 0)); tabHost.addTab(tabHost.newTabSpec(SEARCH_MODE_TOPIC).setIndicator("主题"), SearchHistoryTopicFragment.class, bundle); bundle = new Bundle(); bundle.putString("mode", SEARCH_MODE_BOARD); tabHost.addTab(tabHost.newTabSpec(SEARCH_MODE_BOARD).setIndicator("板块"), SearchHistoryBoardFragment.class, bundle); bundle = new Bundle(); bundle.putString("mode", SEARCH_MODE_USER); tabHost.addTab(tabHost.newTabSpec(SEARCH_MODE_USER).setIndicator("用户"), SearchHistoryUserFragment.class, bundle); tabHost.setOnTabChangedListener(this::updateTabChanged); }
mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String s) {
@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); }
protected void initView() { //实例化布局对象 layoutInflater = LayoutInflater.from(this); //实例化TabHost对象,得到TabHost mTabHost = findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); //得到fragment的个数 int count = fragmentArray.length; for (int i = 0; i < count; i++) { //为每一个Tab按钮设置图标、文字和内容 TabHost.TabSpec tabSpec = mTabHost.newTabSpec(getResources().getString(mTextviewArray[i])).setIndicator(getTabItemView(i)); //将Tab按钮添加进Tab选项卡中 mTabHost.addTab(tabSpec, fragmentArray[i], null); //设置Tab按钮的背景 // mTabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.selector_tab_background); } mTabHost.getTabWidget().setShowDividers(LinearLayout.SHOW_DIVIDER_NONE); //去掉每个tab之间的分割线 mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String s) { position = mTabHost.getCurrentTab(); upDateTab(mTabHost); //tab切换时设置滤镜 } }); mTabHost.setCurrentTab(position); upDateTab(mTabHost); //初始化设置滤镜 }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_list, container, false); tabHost = (FragmentTabHost)view.findViewById(R.id.tab_host); tabHost.setup(getActivity(), getChildFragmentManager(), android.R.id.tabcontent); tabHost.addTab(tabHost.newTabSpec("Live") .setIndicator(getTabView(getString(R.string.live_titile))), FragmentLiveList.class, null); tabHost.addTab(tabHost.newTabSpec("Record") .setIndicator(getTabView(getString(R.string.str_record))), FragmentRecordList.class, null); tabHost.setCurrentTabByTag("Live"); tabHost.getTabWidget().setDividerDrawable(null); updateTab(tabHost); tabHost.setOnTabChangedListener(this); return view; }
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
mTabHost.newTabSpec("additional_nfo").setIndicator( "Additional Info"), AdditionalInfo.class, null); mTabHost.setOnTabChangedListener(this); setTabsStyle(); mTabHost.setCurrentTab(0);
private void initView() { //测试栏目的题目统计TextView mCount = (TextView) findViewById(R.id.tv_count); mDoubleClickExit = new DoubleClickExitHelper(this); Indicator[] indicators = Indicator.values(); mFragmentTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mFragmentTabHost.setup(getApplicationContext(), getSupportFragmentManager(), R.id.realtabcontent); //初始化Tab for (int i = 0; i < indicators.length; i++){ TabHost.TabSpec tabSpec = mFragmentTabHost.newTabSpec(getString(indicators[i].getResName())); tabSpec.setIndicator(getIndicatorView(indicators[i])); mFragmentTabHost.addTab(tabSpec, indicators[i].getClz(), null); } //去除底部按钮之间的分割线 if (android.os.Build.VERSION.SDK_INT > 10) { mFragmentTabHost.getTabWidget().setShowDividers(0); mFragmentTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { if(tabId.equals(getString(Indicator.TEST.getResName()))){ mCount.setVisibility(View.VISIBLE); }else{ mCount.setVisibility(View.GONE); } } }); }}