0

I have bottomNavigation in my android app as shown below in picture. It works fine if I just click on home, cart and other bottomNavigation Items.

As you can see in picture that user can navigate to all categories in home. If I navigate to AllCategoriesFragment then in home item will be selected in bottomNavigation which is correct behavior. But if I go to cart and then click again on home then it shows AllCategoriesFragment which is also correct behavior but in BottomNavigation it doesnt highlight the home items, instead it keep cart item highlighted.

How I can get rid of this issue? Or how I can highlight the bottomNavigation selected item programmatically?

enter image description here

Zohab Ali
  • 8,426
  • 4
  • 55
  • 63

1 Answers1

0

I did it programmatically like by getting activity reference inside fragment andd then getting navView from it and afterwards set the check state of the item to true

activity?.let {
            val navView = it.findViewById<BottomNavigationView>(R.id.nav_view)
            navView.menu.getItem(0).setChecked(true)
        }
Zohab Ali
  • 8,426
  • 4
  • 55
  • 63