Reputation: 11
I'm trying to setup searchBar with NavController, to use the back button as navigate up while in a fragment not registered in the AppBarConfiguration.
I'm currently using MDC 1.9.0-rc01.
The documentation of search bar it's not complete about this usage.
I've tried to setup using setupActionBarWithNavController and didn't work. The menu and back button don't appear while navigating between fragments and the search icon don't show either.
I've also tried to use setupWithNavController passing the searchBar as argument, but didn't work.
The expected behavior is to show the back button when navigating to a secondary fragment, and when clicking back button, it must navigate to the main fragment. As toolbar works
UPDATE:
I've managed to fix it using onDestinationChanged and calling these methods. But if anyone know how to properly setup, i still appreciate it.
searchBar.setNavigationIcon(R.drawable.ic_arrow_back);
searchBar.setNavigationOnClickListener(v -> {
navController.navigateUp();
});
Upvotes: 1
Views: 61