How to fix Android studio 3.5 navigation activity template onNavigationItemSelected not working

后端 未结 5 442
自闭症患者
自闭症患者 2020-12-16 23:16

I created a new navigation drawer activity from Android Studio 3.5 templates, but menu items are not clickable even though I\'m listening for NavigationItemSelected

5条回答
  •  情歌与酒
    2020-12-16 23:54

    **

    For Menu Items Clickable

    ** NavController offers an OnDestinationChangedListener interface that is called when the NavController's current destination or its arguments change. A new listener can be registered via the addOnDestinationChangedListener() method. Note that when calling addOnDestinationChangedListener(), if the current destination exists, it is immediately sent to your listener.

    ////////////////////////////////////////////////////////////////////////

    navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {
       @Override
       public void onDestinationChanged(@NonNull NavController controller,
               @NonNull NavDestination destination, @Nullable Bundle arguments) {
           if(destination.getId() == R.id.gallery) {
               //statements
           } else {
           //statements
    }
       }
    });
    

提交回复
热议问题