Skip to content Skip to sidebar Skip to footer

Bottomnavigation Menu With Jetpack Navigation Does Not Navigate

I have a strange problem regarding a BottomNavigationBar which I could not solve altough having spent a huge amount of time into it. When I use it in the 'recommended' way (from ma

Solution 1:

onCreateView is a method of a Fragment, not a method on Activity, so your method in your MainActivity isn't ever called by the framework.

In fact, that code isn't what you'd use in an Activity at all as per the View Binding documentation.

Therefore your MainActivity should instead look like:

publicclassMainActivityextendsAppCompatActivity  {
   
    private  ActivityMainBinding binding;

    @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Inflate, and then call setContentView() on the returned view root
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        
        NavControllernavController= Navigation.findNavController(this,
            R.id.navHostfragment);
        NavigationUI.setupWithNavController(binding.bottomNavigation, navController);
    }
}

Post a Comment for "Bottomnavigation Menu With Jetpack Navigation Does Not Navigate"