'BottomNavigationView setOnNavigationItemReselectedListener is deprecated in Material Component version 1.4.0. What to use now?

BottomNavigationView setOnNavigationItemReselectedListener is deprecated with Material Component version 1.4.0.

What to use now?



Solution 1:[1]

As per the deprecation message:

Use NavigationBarView#setOnItemReselectedListener(OnItemReselectedListener) instead.

So just replace setOnNavigationItemReselectedListener with setOnItemReselectedListener and change your listener to a NavigationBarView.OnItemReselectedListener.

Solution 2:[2]

Based on the documentation, it seems like you can call the listener interface directly and it will set the listeners internally since it's supported by both bottom navigation and navigation rail now.

https://github.com/material-components/material-components-android/blob/95a769c373792d2fce70d7ee21f3857f65e9d74e/docs/components/NavigationRail.md

NavigationBarView.OnItemSelectedListener { item ->
    when(item.itemId) {
        R.id.item1 -> {
            // Respond to navigation item 1 click
            true
        }
        R.id.item2 -> {
            // Respond to navigation item 2 click
            true
        }
        else -> false
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ianhanniballake
Solution 2 Enes Zorkol