2

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 !

raphheuhh
  • 53
  • 5

1 Answers1

1

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

Javlon
  • 1,108
  • 2
  • 15
  • 29