Do action when holding a button from bottom navigation bar

Issue

I wanted to enter a settings page when I hold down the home button on the bottom navigation bar. I looked for how to get the id of a button in the bottom navigation but couldn’t find anything.

Do you know if I can get a button from this bar?

Thanks !

Solution

Try this code:

binding.bottomNav.menu.forEach {
        if (it.itemId == R.id.home) {
            binding.bottomNav.findViewById<View>(it.itemId).setOnLongClickListener {

                // your action

                true
            }
        }
    }

It iterates through all the menu items of the BottomNavView and sets LongClickListener for the desired menu item

Answered By – Javlon

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published