I am currently building an app with admin and user. I've used the template bottom navigation menu method. I've created two versions of the menu for admin and user. How will I be able to switch these two out at any point?
Asked
Active
Viewed 38 times
1 Answers
1
to switch between the two versions the bottom navigation menu, you can use the setOnNavigationItemSelectedListener
method in the navigation view. This method allows you to set a listener that will be triggered when the user selects an item from the bottom navigation menu.
You can then use an if-else statement to determine if the user is an admin or a user and switch out the menus accordingly. You can also use the getMenu method to get the menu items and then use the setVisible method to hide or show certain menu items.

Mukund Jogi
- 1,329
- 5
- 18

WolCarlos
- 11
- 3
-
So if i had a login page how could i change it depending on the button click of login – 3.14159265358979323 Jan 20 '23 at 12:17
-
You can switch between the two bottom navigation menus by using a switch statement or an if-else statement to check the user's role (admin or user) and then inflate the appropriate menu. For example, in your main activity's onCreate method, you can check the user's role and then call the appropriate method to inflate the correct menu layout. Here is an example using a switch statement: – WolCarlos Jan 20 '23 at 15:56
-
String userRole = getUserRole(); switch (userRole) { case "admin": inflateAdminBottomNav(); break; case "user": inflateUserBottomNav(); break; default: inflateUserBottomNav(); break; } – WolCarlos Jan 20 '23 at 15:56
-
You will have to create methods inflateAdminBottomNav() and inflateUserBottomNav() that will inflate the respective bottom navigation menu. You can also use Fragments to switch between the two bottom navigation menus, where each menu is a fragment and you switch between the two fragments as per the role of the user. – WolCarlos Jan 20 '23 at 15:57