Bottom navigation view doesn't handle back botton action

328 Views Asked by At

I'm new in android programming and sorry for my poor english In my android app there is a bottom navigation with 5 items They work great but i have a problem with back button Imagine item 2 is showing its fragment and when user press back button item 1 fragment's is shows but in bottom navigation item 2 seems to be running How could i fix this bug? Thanks

2

There are 2 best solutions below

1
Henry Hieu On

There are 2 ways:

  • You could handle the onBackPressed on the activity then set the current page for bottomnavigationview
  • Check the current page of the viewpager then set current item for the bottomnavigationview
0
Krutika Chotara On

You can do like this
mBottomNavigationView.getMenu().getItem(0).setChecked(true);

here getItem(0) will be count of bottom navigation view item