How to dynamically hide a menu item in BottomNavigationView?
mBottomNavigationView.getMenu().removeItem(R.id.item_name);
removeItem does the trick. Not sure why setVisible method is not working.
How to hide and show a menu in BottomNavigationView?
bottomNavigation.getMenu().removeItem(R.id.nav_user_download);
removeItem(int menu_item_id),call this method.
i have try hide/show method @Sachin Rao, but it work not very well. so i finally found this way, it's work well for me.
How to disable menu item of bottom navigation view?
You should get the menu of your BottomNavigationView
and then find and disable the MenuItem
that you want. In code it could be done as follows
override fun onCreate(savedInstanceState: Bundle?) {
// Find the bottom navigation view, (Use correct ID)
// menu_item_1 is probably not a good ID for a navigation view
val navView: BottomNavigationView = findViewById(R.id.nav_view)
// Find the menu item and then disable it
navView.menu.findItem(R.id.navigation_home).isEnabled = false
}
Hide or remove static menu item in Android
I found solution here
How to dynamically hide a menu item in BottomNavigationView?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
// This is a way to hide static menu item
navigation.getMenu().removeItem(R.id.navigation_home);
...
}
how to hide BottomNavigationView on android-navigation lib
You could do something like this in your activity's onCreate. When ever an item in the nav bar is selected it will show or hide the nav based on the fragment id's.
private fun setupNav() {
val navController = findNavController(R.id.nav_host_fragment)
findViewById<BottomNavigationView>(R.id.bottomNav)
.setupWithNavController(navController)
navController.addOnDestinationChangedListener { _, destination, _ ->
when (destination.id) {
R.id.mainFragment -> showBottomNav()
R.id.mineFragment -> showBottomNav()
else -> hideBottomNav()
}
}
}
private fun showBottomNav() {
bottomNav.visibility = View.VISIBLE
}
private fun hideBottomNav() {
bottomNav.visibility = View.GONE
}
Menu item visibility doesnt change partly
In order to make sure that mAuth.currentUser
is null
, you need to add a listener when the user has logged out so that you can update visibility of menu items; because you might call updateUI()
before the user sign out, so mAuth.currentUser
still has a value.
So in onNavigationItemSelected()
callback: add this listener
R.id.nav_logout_item->{
mAuth.signOut()
AuthUI.getInstance()
.signOut(this) // context
.addOnCompleteListener {
// User has been logged out
updateUI()
}
}
And do the same for the login behavior to return the visibility back to the menu items.
Android - Add bottom navigation view dynamically
This is a bug of BottomNavigationView
.
Here is the bug reference: https://issuetracker.google.com/issues/37124043
This has been fixed in support library 25.0.1
. Update your support library
and try again.
Hope this will help~
Related Topics
Detect or Prevent If User Uses Fake Location
React Native: Java_Home Is Not Set and No 'Java' Command Could Be Found in Your Path
Play Store Alpha Test Download Link Not Working
Remove Old Fragment from Fragment Manager
Scrollview Not Scrolling in Android Bottomsheet
How to Avoid the Frame Layout Is Pushed Up When the Soft Keyboard Appears
How to Connect Existing Android Studio Project to Existing Github Repository
How to Delete Shared Preferences Data from App in Android
Android Volley Basicnetwork.Performrequest() Unexpected Response Code 404
How to Know Location Area Code and Cell Id in Android Phone
How to Create a Video from an Array of Images in Android
How to Tell If a View Is Visible on Screen in Android
How to Refresh the Fragment After Activity Finished in Android
How to Create a Folder in Android External Storage Directory