Java Code Examples for android.support.v4.app.FragmentTabHost#setOnTabChangedListener()

The following examples show how to use android.support.v4.app.FragmentTabHost#setOnTabChangedListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From FragmentTabHost with Apache License 2.0 5 votes vote down vote up
private void initTabHost() {
    //实例化FragmentTabHost对象
    FragmentTabHost fragmentTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    fragmentTabHost.setup(this,getSupportFragmentManager(),android.R.id.tabcontent);

    //去掉分割线
    fragmentTabHost.getTabWidget().setDividerDrawable(null);

    for (int i = 0; i<mTableItemList.size(); i++) {
        TabItem tabItem = mTableItemList.get(i);
        //实例化一个TabSpec,设置tab的名称和视图
        TabHost.TabSpec tabSpec = fragmentTabHost.newTabSpec(tabItem.getTitleString()).setIndicator(tabItem.getView());
        fragmentTabHost.addTab(tabSpec,tabItem.getFragmentClass(),null);

        //给Tab按钮设置背景
        fragmentTabHost.getTabWidget().getChildAt(i).setBackgroundColor(getResources().getColor(R.color.main_bottom_bg));

        //默认选中第一个tab
        if(i == 0) {
            tabItem.setChecked(true);
        }
    }

    fragmentTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            //重置Tab样式
            for (int i = 0; i< mTableItemList.size(); i++) {
                TabItem tabitem = mTableItemList.get(i);
                if (tabId.equals(tabitem.getTitleString())) {
                    tabitem.setChecked(true);
                }else {
                    tabitem.setChecked(false);
                }
            }
        }
    });
}
 
Example 2
Source File: MainActivity.java    From AndroidReview with GNU General Public License v3.0 5 votes vote down vote up
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);
                }
            }
        });
}}
 
Example 3
Source File: MainFrameActivity.java    From pixate-freestyle-android with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
private void initTabs() {
    tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    tabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
    tabHost.setOnTabChangedListener(this);
    tabs = (TabWidget) findViewById(android.R.id.tabs);
    // tabs.setShowDividers(TabWidget.SHOW_DIVIDER_NONE);

    addTab(R.drawable.tab_icon_typography, TypographyContainer.class);
    addTab(R.drawable.tab_icon_listview, ListViewContainer.class);
    addTab(R.drawable.tab_icon_gridview, GridViewContainer.class);
    addTab(R.drawable.tab_icon_buttons, ButtonsContainer.class);
    addTab(R.drawable.tab_icon_icons, IconsContainer.class);
}
 
Example 4
Source File: ProfileFragment.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
private void initViews(final View view) {

        mOwnerImageView = (RoundedCornerImageView) view.findViewById(R.id.image_user);
        mChatImageView = (ImageView) view.findViewById(R.id.chat_with_owner);

        mChatImageView.setOnClickListener(this);
        mOwnerNameTextView = (TextView) view.findViewById(R.id.text_user_name);
        mOwnerBarterLocationTextView = (TextView) view
                .findViewById(R.id.text_user_location);
        mDragHandle = view.findViewById(R.id.container_profile_info);

        mTabHost = (FragmentTabHost) view.findViewById(android.R.id.tabhost);
        mTabHost.setup(getActivity(), getChildFragmentManager(), android.R.id.tabcontent);
        mTabHost.addTab(mTabHost.newTabSpec(FragmentTags.ABOUT_ME)
                        .setIndicator(getString(R.string.about_me)), DummyFragment.class,
                null
        );
        mTabHost.addTab(mTabHost.newTabSpec(FragmentTags.MY_BOOKS)
                        .setIndicator(getString(R.string.my_books)), DummyFragment.class,
                null
        );
        mTabHost.setOnTabChangedListener(this);

        mViewPager = (ViewPager) view.findViewById(R.id.pager_profile);
        mProfileFragmentsAdapter = new ProfileFragmentsAdapter(getChildFragmentManager());
        mViewPager.setAdapter(mProfileFragmentsAdapter);
        mViewPager.setOnPageChangeListener(this);

    }