After spending a lot of time and not finding a suitable solution, I decided to turn to this service for help.
I have an example of the simplest application that implements Drawer. This example contains only menu items without any implementations. In the menu item Share, I added a Switch and a listener to it:
main_nav.xml
<item
    android:id="@+id/nav_share"
    android:icon="@drawable/ic_menu_share"
    app:actionViewClass="androidx.appcompat.widget.SwitchCompat"
    android:title="@string/menu_share" />
MainActivity.kt
  val menuItem = navigation_view.menu.findItem(R.id.nav_share)
  val switch_id = menuItem.actionView as SwitchCompat
  switch_id.isChecked = true
  switch_id.setOnClickListener {
   // TODO: empty scope
  }
The switch works smoothly and with animation as shown below:
But now I need to turn off the Home menu item if the Switch is off:
switch_id.setOnClickListener {
     navigation_view.menu.findItem(R.id.nav_home).isEnabled = switch_id.isChecked
}
After adding this line, my Switch animation breaks!
I spent two days solving this issue and in the end to no avail.
My question: WTF with android menu in 2021? Why does accessing a menu item break the animation and how can I fix it? I would be grateful for any help !!


