BottomNavigationView - How to uncheck all MenuItems and keep Titles being displayed?

后端 未结 10 1238
面向向阳花
面向向阳花 2020-12-18 19:33

As I liked the design from BottomNavigationView I decided to implement a new Menu for my App with it, instead of just using simple buttons.

I took this

10条回答
  •  有刺的猬
    2020-12-18 20:05

    To unselect all items I have create this extension:

    fun BottomNavigationView.uncheckAllItems() {
        menu.setGroupCheckable(0, true, false)
        for (i in 0 until menu.size()) {
            menu.getItem(i).isChecked = false
        }
        menu.setGroupCheckable(0, true, true)
    }
    

    menu.setGroupCheckable(0, true, false) make it possible. The third parameter made the menu not exclusive and then within the loop you change the checked status. To finish set the menu to exclusive again.

    Here the doc

提交回复
热议问题