I have two fragments in my app namely HomeFragment and FeedbackFragment. In addition to switching fragments on tab buttons, I would also need to switch between fragments on a button click that is within the fragment. The tab items are highlighted properly on switching fragments using tab clicks. But the tab items does not get highlighted when i switch to other fragment on a button click from fragment1
Below is the code used to switch across fragments on button click and it works.
FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
But the respective tab icon of FeedbackFragment is not highlighted. Currently the navigation item of HomeFragment remains highlighted even after FeedbackFragment is replaced. How do I highlight the menu item of Feedback Fragment ?
I tried below approaches but nothing worked:
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.navigation);
View view = bottomNavigationView.findViewById(R.id.tab_calls);
view.performClick();
Also,
MainActivity.mBottomBar.selectTabAtPosition(2);
Nothing worked. Please help.