Search in sources :

Example 1 with OnTabSelectListener

use of com.flyco.tablayout.listener.OnTabSelectListener in project FlycoTabLayout by H07000223.

the class SegmentTabActivity method tl_3.

private void tl_3() {
    final ViewPager vp_3 = ViewFindUtils.find(mDecorView, R.id.vp_2);
    vp_3.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
    mTabLayout_3.setTabData(mTitles_3);
    mTabLayout_3.setOnTabSelectListener(new OnTabSelectListener() {

        @Override
        public void onTabSelect(int position) {
            vp_3.setCurrentItem(position);
        }

        @Override
        public void onTabReselect(int position) {
        }
    });
    vp_3.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            mTabLayout_3.setCurrentTab(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    vp_3.setCurrentItem(1);
}
Also used : OnTabSelectListener(com.flyco.tablayout.listener.OnTabSelectListener) ViewPager(android.support.v4.view.ViewPager)

Example 2 with OnTabSelectListener

use of com.flyco.tablayout.listener.OnTabSelectListener in project FlycoTabLayout by H07000223.

the class CommonTabActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_common_tab);
    for (String title : mTitles) {
        mFragments.add(SimpleCardFragment.getInstance("Switch ViewPager " + title));
        mFragments2.add(SimpleCardFragment.getInstance("Switch Fragment " + title));
    }
    for (int i = 0; i < mTitles.length; i++) {
        mTabEntities.add(new TabEntity(mTitles[i], mIconSelectIds[i], mIconUnselectIds[i]));
    }
    mDecorView = getWindow().getDecorView();
    mViewPager = ViewFindUtils.find(mDecorView, R.id.vp_2);
    mViewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
    /**
     * with nothing
     */
    mTabLayout_1 = ViewFindUtils.find(mDecorView, R.id.tl_1);
    /**
     * with ViewPager
     */
    mTabLayout_2 = ViewFindUtils.find(mDecorView, R.id.tl_2);
    /**
     * with Fragments
     */
    mTabLayout_3 = ViewFindUtils.find(mDecorView, R.id.tl_3);
    /**
     * indicator固定宽度
     */
    mTabLayout_4 = ViewFindUtils.find(mDecorView, R.id.tl_4);
    /**
     * indicator固定宽度
     */
    mTabLayout_5 = ViewFindUtils.find(mDecorView, R.id.tl_5);
    /**
     * indicator矩形圆角
     */
    mTabLayout_6 = ViewFindUtils.find(mDecorView, R.id.tl_6);
    /**
     * indicator三角形
     */
    mTabLayout_7 = ViewFindUtils.find(mDecorView, R.id.tl_7);
    /**
     * indicator圆角色块
     */
    mTabLayout_8 = ViewFindUtils.find(mDecorView, R.id.tl_8);
    mTabLayout_1.setTabData(mTabEntities);
    tl_2();
    mTabLayout_3.setTabData(mTabEntities, this, R.id.fl_change, mFragments2);
    mTabLayout_4.setTabData(mTabEntities);
    mTabLayout_5.setTabData(mTabEntities);
    mTabLayout_6.setTabData(mTabEntities);
    mTabLayout_7.setTabData(mTabEntities);
    mTabLayout_8.setTabData(mTabEntities);
    mTabLayout_3.setOnTabSelectListener(new OnTabSelectListener() {

        @Override
        public void onTabSelect(int position) {
            mTabLayout_1.setCurrentTab(position);
            mTabLayout_2.setCurrentTab(position);
            mTabLayout_4.setCurrentTab(position);
            mTabLayout_5.setCurrentTab(position);
            mTabLayout_6.setCurrentTab(position);
            mTabLayout_7.setCurrentTab(position);
            mTabLayout_8.setCurrentTab(position);
        }

        @Override
        public void onTabReselect(int position) {
        }
    });
    mTabLayout_8.setCurrentTab(2);
    mTabLayout_3.setCurrentTab(1);
    // 显示未读红点
    mTabLayout_1.showDot(2);
    mTabLayout_3.showDot(1);
    mTabLayout_4.showDot(1);
    // 两位数
    mTabLayout_2.showMsg(0, 55);
    mTabLayout_2.setMsgMargin(0, -5, 5);
    // 三位数
    mTabLayout_2.showMsg(1, 100);
    mTabLayout_2.setMsgMargin(1, -5, 5);
    // 设置未读消息红点
    mTabLayout_2.showDot(2);
    MsgView rtv_2_2 = mTabLayout_2.getMsgView(2);
    if (rtv_2_2 != null) {
        UnreadMsgUtils.setSize(rtv_2_2, dp2px(7.5f));
    }
    // 设置未读消息背景
    mTabLayout_2.showMsg(3, 5);
    mTabLayout_2.setMsgMargin(3, 0, 5);
    MsgView rtv_2_3 = mTabLayout_2.getMsgView(3);
    if (rtv_2_3 != null) {
        rtv_2_3.setBackgroundColor(Color.parseColor("#6D8FB0"));
    }
}
Also used : TabEntity(com.flyco.tablayoutsamples.entity.TabEntity) CustomTabEntity(com.flyco.tablayout.listener.CustomTabEntity) MsgView(com.flyco.tablayout.widget.MsgView) OnTabSelectListener(com.flyco.tablayout.listener.OnTabSelectListener)

Example 3 with OnTabSelectListener

use of com.flyco.tablayout.listener.OnTabSelectListener in project Android-skin-support by ximsfei.

the class CommonTabActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_common_tab);
    for (String title : mTitles) {
        mFragments.add(SimpleCardFragment.getInstance("Switch ViewPager " + title));
        mFragments2.add(SimpleCardFragment.getInstance("Switch Fragment " + title));
    }
    for (int i = 0; i < mTitles.length; i++) {
        mTabEntities.add(new TabEntity(mTitles[i], mIconSelectIds[i], mIconUnselectIds[i]));
    }
    mDecorView = getWindow().getDecorView();
    mViewPager = ViewFindUtils.find(mDecorView, R.id.vp_2);
    mViewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
    /** with nothing */
    mTabLayout_1 = ViewFindUtils.find(mDecorView, R.id.t2_1);
    /** with ViewPager */
    mTabLayout_2 = ViewFindUtils.find(mDecorView, R.id.t2_2);
    /** with Fragments */
    mTabLayout_3 = ViewFindUtils.find(mDecorView, R.id.t2_3);
    /** indicator固定宽度 */
    mTabLayout_4 = ViewFindUtils.find(mDecorView, R.id.t2_4);
    /** indicator固定宽度 */
    mTabLayout_5 = ViewFindUtils.find(mDecorView, R.id.t2_5);
    /** indicator矩形圆角 */
    mTabLayout_6 = ViewFindUtils.find(mDecorView, R.id.t2_6);
    /** indicator三角形 */
    mTabLayout_7 = ViewFindUtils.find(mDecorView, R.id.t2_7);
    /** indicator圆角色块 */
    mTabLayout_8 = ViewFindUtils.find(mDecorView, R.id.t2_8);
    mTabLayout_1.setTabData(mTabEntities);
    tl_2();
    mTabLayout_3.setTabData(mTabEntities, this, R.id.fl_change, mFragments2);
    mTabLayout_4.setTabData(mTabEntities);
    mTabLayout_5.setTabData(mTabEntities);
    mTabLayout_6.setTabData(mTabEntities);
    mTabLayout_7.setTabData(mTabEntities);
    mTabLayout_8.setTabData(mTabEntities);
    mTabLayout_3.setOnTabSelectListener(new OnTabSelectListener() {

        @Override
        public void onTabSelect(int position) {
            mTabLayout_1.setCurrentTab(position);
            mTabLayout_2.setCurrentTab(position);
            mTabLayout_4.setCurrentTab(position);
            mTabLayout_5.setCurrentTab(position);
            mTabLayout_6.setCurrentTab(position);
            mTabLayout_7.setCurrentTab(position);
            mTabLayout_8.setCurrentTab(position);
        }

        @Override
        public void onTabReselect(int position) {
        }
    });
    mTabLayout_8.setCurrentTab(2);
    mTabLayout_3.setCurrentTab(1);
    //显示未读红点
    mTabLayout_1.showDot(2);
    MsgView rtv_1_2 = mTabLayout_1.getMsgView(2);
    if (rtv_1_2 != null) {
        if (rtv_1_2 instanceof SkinMsgView) {
            ((SkinMsgView) rtv_1_2).setBackgroundColorResource(R.color.msg_background_color);
        }
    }
    mTabLayout_3.showDot(1);
    MsgView rtv_3_1 = mTabLayout_3.getMsgView(1);
    if (rtv_3_1 != null) {
        if (rtv_3_1 instanceof SkinMsgView) {
            ((SkinMsgView) rtv_3_1).setBackgroundColorResource(R.color.msg_background_color);
        }
    }
    mTabLayout_4.showDot(1);
    MsgView rtv_4_1 = mTabLayout_4.getMsgView(1);
    if (rtv_4_1 != null) {
        if (rtv_4_1 instanceof SkinMsgView) {
            ((SkinMsgView) rtv_4_1).setBackgroundColorResource(R.color.msg_background_color);
        }
    }
    //两位数
    mTabLayout_2.showMsg(0, 55);
    MsgView rtv_2_0 = mTabLayout_2.getMsgView(0);
    if (rtv_2_0 != null) {
        if (rtv_2_0 instanceof SkinMsgView) {
            ((SkinMsgView) rtv_2_0).setBackgroundColorResource(R.color.msg_background_color);
        }
    }
    mTabLayout_2.setMsgMargin(0, -5, 5);
    //三位数
    mTabLayout_2.showMsg(1, 100);
    MsgView rtv_2_1 = mTabLayout_2.getMsgView(1);
    if (rtv_2_1 != null) {
        if (rtv_2_1 instanceof SkinMsgView) {
            ((SkinMsgView) rtv_2_1).setBackgroundColorResource(R.color.msg_background_color);
        }
    }
    mTabLayout_2.setMsgMargin(1, -5, 5);
    //设置未读消息红点
    mTabLayout_2.showDot(2);
    MsgView rtv_2_2 = mTabLayout_2.getMsgView(2);
    if (rtv_2_2 != null) {
        UnreadMsgUtils.setSize(rtv_2_2, dp2px(7.5f));
    }
    //设置未读消息背景
    mTabLayout_2.showMsg(3, 5);
    mTabLayout_2.setMsgMargin(3, 0, 5);
    MsgView rtv_2_3 = mTabLayout_2.getMsgView(3);
    if (rtv_2_3 != null) {
        if (rtv_2_3 instanceof SkinMsgView) {
            ((SkinMsgView) rtv_2_3).setBackgroundColorResource(R.color.msg_background_color);
            ((SkinMsgView) rtv_2_3).setStrokeColorResource(R.color.msg_stroke_color);
        } else {
            rtv_2_3.setBackgroundColor(Color.parseColor("#6D8FB0"));
        }
    }
}
Also used : TabEntity(com.ximsfei.skindemo.flycotablayout.entity.TabEntity) CustomTabEntity(com.flyco.tablayout.listener.CustomTabEntity) SkinMsgView(skin.support.flycotablayout.widget.SkinMsgView) SkinMsgView(skin.support.flycotablayout.widget.SkinMsgView) MsgView(com.flyco.tablayout.widget.MsgView) OnTabSelectListener(com.flyco.tablayout.listener.OnTabSelectListener)

Example 4 with OnTabSelectListener

use of com.flyco.tablayout.listener.OnTabSelectListener in project Android-skin-support by ximsfei.

the class CommonTabActivity method tl_2.

private void tl_2() {
    mTabLayout_2.setTabData(mTabEntities);
    mTabLayout_2.setOnTabSelectListener(new OnTabSelectListener() {

        @Override
        public void onTabSelect(int position) {
            mViewPager.setCurrentItem(position);
        }

        @Override
        public void onTabReselect(int position) {
            if (position == 0) {
                mTabLayout_2.showMsg(0, mRandom.nextInt(100) + 1);
            //                    UnreadMsgUtils.show(mTabLayout_2.getMsgView(0), mRandom.nextInt(100) + 1);
            }
        }
    });
    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            mTabLayout_2.setCurrentTab(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    mViewPager.setCurrentItem(1);
}
Also used : OnTabSelectListener(com.flyco.tablayout.listener.OnTabSelectListener) ViewPager(android.support.v4.view.ViewPager)

Example 5 with OnTabSelectListener

use of com.flyco.tablayout.listener.OnTabSelectListener in project Android-skin-support by ximsfei.

the class SegmentTabActivity method tl_3.

private void tl_3() {
    final ViewPager vp_3 = ViewFindUtils.find(mDecorView, R.id.vp_2);
    vp_3.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
    mTabLayout_3.setTabData(mTitles_3);
    mTabLayout_3.setOnTabSelectListener(new OnTabSelectListener() {

        @Override
        public void onTabSelect(int position) {
            vp_3.setCurrentItem(position);
        }

        @Override
        public void onTabReselect(int position) {
        }
    });
    vp_3.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            mTabLayout_3.setCurrentTab(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    vp_3.setCurrentItem(1);
}
Also used : OnTabSelectListener(com.flyco.tablayout.listener.OnTabSelectListener) ViewPager(android.support.v4.view.ViewPager)

Aggregations

OnTabSelectListener (com.flyco.tablayout.listener.OnTabSelectListener)6 ViewPager (android.support.v4.view.ViewPager)4 CustomTabEntity (com.flyco.tablayout.listener.CustomTabEntity)2 MsgView (com.flyco.tablayout.widget.MsgView)2 TabEntity (com.flyco.tablayoutsamples.entity.TabEntity)1 TabEntity (com.ximsfei.skindemo.flycotablayout.entity.TabEntity)1 SkinMsgView (skin.support.flycotablayout.widget.SkinMsgView)1