Search in sources :

Example 1 with OnTabItemSelectedListener

use of me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener in project PagerBottomTabStrip by tyzlmjj.

the class CustomItemLayout method setSelect.

@Override
public void setSelect(int index) {
    //重复选择
    if (index == mSelected) {
        for (OnTabItemSelectedListener listener : mListeners) {
            listener.onRepeat(mSelected);
        }
        return;
    }
    //记录前一个选中项和当前选中项
    int oldSelected = mSelected;
    mSelected = index;
    //前一个选中项必须不小于0才有效
    if (oldSelected >= 0) {
        mItems.get(oldSelected).setChecked(false);
    }
    mItems.get(mSelected).setChecked(true);
    //事件回调
    for (OnTabItemSelectedListener listener : mListeners) {
        listener.onSelected(mSelected, oldSelected);
    }
}
Also used : OnTabItemSelectedListener(me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener)

Example 2 with OnTabItemSelectedListener

use of me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener in project PagerBottomTabStrip by tyzlmjj.

the class MaterialItemLayout method setSelect.

private void setSelect(int index, float x, float y) {
    //重复选择
    if (index == mSelected) {
        for (OnTabItemSelectedListener listener : mListeners) {
            listener.onRepeat(mSelected);
        }
        return;
    }
    //记录前一个选中项和当前选中项
    mOldSelected = mSelected;
    mSelected = index;
    mDelayedAnimationHelper.beginDelayedTransition(this);
    //切换背景颜色
    if (mChangeBackgroundMode) {
        addOvalColor(mColors.get(mSelected), x, y);
    }
    //前一个选中项必须不小于0才有效
    if (mOldSelected >= 0) {
        mItems.get(mOldSelected).setChecked(false);
    }
    mItems.get(mSelected).setChecked(true);
    //事件回调
    for (OnTabItemSelectedListener listener : mListeners) {
        listener.onSelected(mSelected, mOldSelected);
    }
}
Also used : OnTabItemSelectedListener(me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener)

Example 3 with OnTabItemSelectedListener

use of me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener in project PagerBottomTabStrip by tyzlmjj.

the class MaterialDesignActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.show);
    PageBottomTabLayout pageBottomTabLayout = (PageBottomTabLayout) findViewById(tab);
    mNavigationController = pageBottomTabLayout.material().addItem(R.drawable.ic_ondemand_video_black_24dp, "Movies & TV", testColors[0]).addItem(R.drawable.ic_audiotrack_black_24dp, "Music", testColors[1]).addItem(R.drawable.ic_book_black_24dp, "Books", testColors[2]).addItem(R.drawable.ic_news_black_24dp, "Newsstand", testColors[3]).setDefaultColor(//未选中状态的颜色
    0x89FFFFFF).setMode(//这里可以设置样式模式,总共可以组合出4种效果
    MaterialMode.CHANGE_BACKGROUND_COLOR | MaterialMode.HIDE_TEXT).build();
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setAdapter(new MyViewPagerAdapter(getSupportFragmentManager(), mNavigationController.getItemCount()));
    //自动适配ViewPager页面切换
    mNavigationController.setupWithViewPager(viewPager);
    //也可以设置Item选中事件的监听
    mNavigationController.addTabItemSelectedListener(new OnTabItemSelectedListener() {

        @Override
        public void onSelected(int index, int old) {
            Log.i("asd", "selected: " + index + " old: " + old);
        }

        @Override
        public void onRepeat(int index) {
            Log.i("asd", "onRepeat selected: " + index);
        }
    });
//设置消息圆点
//        mNavigationController.setMessageNumber(1,12);
//        mNavigationController.setHasMessage(1,true);
}
Also used : OnTabItemSelectedListener(me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener) MyViewPagerAdapter(me.majiajie.pagerbottomtabstriptest.other.MyViewPagerAdapter) ViewPager(android.support.v4.view.ViewPager) PageBottomTabLayout(me.majiajie.pagerbottomtabstrip.PageBottomTabLayout)

Aggregations

OnTabItemSelectedListener (me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener)3 ViewPager (android.support.v4.view.ViewPager)1 PageBottomTabLayout (me.majiajie.pagerbottomtabstrip.PageBottomTabLayout)1 MyViewPagerAdapter (me.majiajie.pagerbottomtabstriptest.other.MyViewPagerAdapter)1