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

后端 未结 5 436
自闭症患者
自闭症患者 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-17 00:02

    When you call NavigationUI.setupWithNavController(navigationView, navController), you're saying that you want NavController to handle click events from your NavigationView, navigating to the related screen as per the NavigationUI documentation. This, by necessity, calls setNavigationItemSelectedListener() internally, overriding the setNavigationItemSelectedListener() you call earlier in onCreate(). If you've hooked up your NavigationView to fragments in your app (as the template does out of the box), then there is no need to call setNavigationItemSelectedListener yourself.

    Of course, you should ensure that your layout has not changed from what the Navigation Drawer Activity gives you by default - there is a known issue with Android Studio 3.5 that can lead to the order of views being changed which would break cases like DrawerLayout (where the order of children matters greatly)

提交回复
热议问题