Search in sources :

Example 1 with DiscoveryFragment

use of skin.support.mobile.demo.fragment.DiscoveryFragment in project Android-skin-support by ximsfei.

the class MainActivity method initViews.

private void initViews() {
    mFragments = new ArrayList<>();
    mFragments.add(new HomeFragment());
    mFragments.add(new DiscoveryFragment());
    mFragments.add(new MineFragment());
    mContainerVp.setAdapter(new FragmentStateAdapter(this) {

        @NonNull
        @Override
        public Fragment createFragment(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getItemCount() {
            return mFragments.size();
        }
    });
    mContainerVp.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {

        @Override
        public void onPageSelected(int position) {
            mMenuBnv.getMenu().getItem(position).setChecked(true);
            setTitle(mMenuBnv.getMenu().getItem(position).getTitle());
        }
    });
    mMenuBnv.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch(item.getItemId()) {
                case R.id.bnv_home:
                    mContainerVp.setCurrentItem(0);
                    return true;
                case R.id.bnv_discovery:
                    mContainerVp.setCurrentItem(1);
                    return true;
                case R.id.bnv_mine:
                    mContainerVp.setCurrentItem(2);
                    return true;
            }
            return false;
        }
    });
}
Also used : MineFragment(skin.support.mobile.demo.fragment.MineFragment) MenuItem(android.view.MenuItem) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) HomeFragment(skin.support.mobile.demo.fragment.HomeFragment) Fragment(androidx.fragment.app.Fragment) HomeFragment(skin.support.mobile.demo.fragment.HomeFragment) DiscoveryFragment(skin.support.mobile.demo.fragment.DiscoveryFragment) MineFragment(skin.support.mobile.demo.fragment.MineFragment) ViewPager2(androidx.viewpager2.widget.ViewPager2) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) NonNull(androidx.annotation.NonNull) DiscoveryFragment(skin.support.mobile.demo.fragment.DiscoveryFragment)

Aggregations

MenuItem (android.view.MenuItem)1 NonNull (androidx.annotation.NonNull)1 Fragment (androidx.fragment.app.Fragment)1 FragmentStateAdapter (androidx.viewpager2.adapter.FragmentStateAdapter)1 ViewPager2 (androidx.viewpager2.widget.ViewPager2)1 BottomNavigationView (com.google.android.material.bottomnavigation.BottomNavigationView)1 DiscoveryFragment (skin.support.mobile.demo.fragment.DiscoveryFragment)1 HomeFragment (skin.support.mobile.demo.fragment.HomeFragment)1 MineFragment (skin.support.mobile.demo.fragment.MineFragment)1