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;
}
});
}
Aggregations