0

When you select an item in the Bottom Navigation Bar provided by Android Studio it displays a fragment. I want to make a logout item that when you select it, it calls a method but don't actually bring me a fragment.

I understand that NavigationUI set up all the configuration of the navigation bar, so when I try to implement navController.addOnDestinationChangedListener() and add my action to my logout item, I think that overrides the nav configuration and I just can't navigate over the items

Does I have to configure by myself and add a listener on every item?

I also want to make that when a confirmation dialog appears when you clicked the logout item, if u select cancel it returns you to the previous state (EX: I'm in Home fragment, if I click on logout item, and I cancel it, it returns me to the Home fragment)

  • you can check this post https://stackoverflow.com/questions/50514758/how-to-clear-navigation-stack-after-navigating-to-another-fragment-in-android – Andi Tenroaji Ahmad Oct 16 '19 at 00:54

1 Answers1

0

You can enable/disable any menuitem in NavigationView...

NavigationView navigationView= findViewById(R.id.nav_id_in_layout)

Menu menuNav=navigationView.getMenu();
MenuItem nav_item2 = menuNav.findItem(R.id.nav_item2);
nav_item2.setEnabled(false)
abhi
  • 228
  • 3
  • 9