Hide Toolbar Back Arrow With Navigationcomponent And Bottomnavigationview
I'm in the process of implementing NavigationComponent coupled with a BottomNavigationView and I am noticing that the back arrow is shown in the toolbar for all fragment destinatio
Solution 1:
If you are using a AppBarConfiguration should look like this.
val appBarConfiguration = AppBarConfiguration(
setOf(
R.id.homeFragment,
R.id.dashboardFragment,
R.id.notificationsFragment
)
)
setupActionBarWithNavController(navController!!, appBarConfiguration!!)
Which means that all of your fragments are top level destinations.
Heads up , when you hit back , you will get out of the app (or if configured to the first fragment, in BottomSheets you get this behaviour for example). So if you need another case you should configure onBackPressed for each fragment
Solution 2:
the simple way that will remove arrow back icon is to make destination change listener and if destination id == R.id.fragmentYouWantRemoveArrawBack setNavigationIcon(null);
EX:
navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {
@Override
public void onDestinationChanged(@NonNull NavController controller,
@NonNull NavDestination destination,
@Nullable Bundle arguments) {
if (destination.getId() == R.id.myChiehkFrament) {
findViewById(R.id.chat_toolbar_constraintL).setVisibility(View.VISIBLE);
toolbar.setNavigationIcon(null);
} else {
findViewById(R.id.chat_toolbar_constraintL).setVisibility(View.GONE);
}
}});
Solution 3:
Do it like this in kotlin
navController.addOnDestinationChangedListener { _, destination, _ ->
if (destination.id == R.id.searchFragment) {
binding.toolbar.navigationIcon = null
} else {
}
}
Solution 4:
use getActionBar().setDisplayHomeAsUpEnabled(false) to remove home/back button from toolbar
Post a Comment for "Hide Toolbar Back Arrow With Navigationcomponent And Bottomnavigationview"