I did so much researches in the internet and the conclusion was that we cannot use BottomNavigationView
and ViewPager
and TabLayout
simultaneously. but there are a lot of app such as Instagram that merged them.
my question is that how can they do that? do they use a special trick or not?
you can create bottomNavigationView in activity and attach fragment in it with this code when click a on item of it:
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction()
.replace(frameId, fragment, "fragTransaction");
transaction.commit();
and then create a fragment wiht a tabLayout and viewPager to control child fragment in it and you most using to control fragment in viewPagerAdapter
FragmentManager fragmentManager = getChildFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction()
.replace(frameId, fragment, "fragTransaction");
transaction.commit();