Page 197 - MDP2022-2
P. 197

import  github.com.st235.lib_expandablebottombar.ExpandableBottomBar;


            public  class  MainActivity  extends  AppCompatActivity  {


                    @BindView(R.id.bottom_bar)
                    ExpandableBottomBar  bottomBar;


                    @BindView(R.id.main_pager)
                    ViewPager2  mPager;


                    @Override
                    protected  void  onCreate(Bundle  savedInstanceState)  {
                            super.onCreate(savedInstanceState);
                            setContentView(R.layout.activity_main);
                            ButterKnife.bind(this,  this);


                            FragmentStateAdapter  pagerAdapter  =  new  ScreenSlidePagerAdapter(this);


                            mPager.setAdapter(pagerAdapter);
                            mPager.setPageTransformer(new  ZoomOutPageTransformer());
                            mPager.setUserInputEnabled(false);


                            bottomBar.setOnItemSelectedListener((view,  menuItem,  aBoolean)  ->  {
                                    switch  (menuItem.getId())  {
                                            case  R.id.home:
                                                    mPager.setCurrentItem(0);
                                                    break;
                                            case  R.id.list:
                                                    mPager.setCurrentItem(1);
                                                    break;
                                            case  R.id.setting:
                                                    mPager.setCurrentItem(2);
                                                    break;
                                    }


                                    return  null;
                            });
                    }


                    @Override
                    public  void  onBackPressed()  {
                            if  (mPager.getCurrentItem()  ==  0)  {
                                    super.onBackPressed();
                            }  else  {
                                    mPager.setCurrentItem(mPager.getCurrentItem()  -  1);
   192   193   194   195   196   197   198   199   200   201   202