android hide toolbar in specific fragment

前端 未结 9 1426
既然无缘
既然无缘 2021-01-31 08:20

I have a problem that I don\'t know how to solve. How do you hide a toolbar in a specific fragment, I have already been searching around on the internet and what I found was com

9条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-31 08:53

    If you are using the new Navigation Component, add this while setting up the toolbar

    navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {
       @Override
       public void onDestinationChanged(@NonNull NavController controller,
               @NonNull NavDestination destination, @Nullable Bundle arguments) {
           if(destination.getId() == R.id.full_screen_destination) {
               toolbar.setVisibility(View.GONE);
               bottomNavigationView.setVisibility(View.GONE);
           } else {
               toolbar.setVisibility(View.VISIBLE);
               bottomNavigationView.setVisibility(View.VISIBLE);
           }
       }
    });
    

提交回复
热议问题