Agung
Agung

Reputation: 13853

How to check which menu file is inflated in BottomNavigationView?

I use 2 different menu for my bottom navigation view called

  1. bottom_navigation_menu.xml
  2. bottom_navigation_menu_verified.xml

I need to set different action based on what is the current menu inflated in my bottom navigation view. I want to make something like this

lateinit var bottomNavigationView : BottomNavigationView

if (bottomNavigationView.menu == R.menu.bottom_navigation_menu_verified) {
   // do something here
}

but the code above is invalid because bottomNavigationView.menu will return Menu data type and R.menu.bottom_navigation_menu_verified will return int, type doesn't match. so how to check what is the current inflated menu in my bottom navigation view ?

java/kotlin is okay

Upvotes: 1

Views: 406

Answers (1)

Archie.bpgc
Archie.bpgc

Reputation: 24012

You can probably check for a specific MenuItem:

if (null != bottomNavigationView.menu.findItem(R.id.bottom_navigation_menu_item1)) {
   // do something here
}

Upvotes: 2

Related Questions