BottomNavigationView整体隐藏

一个需求,在登录注册的时候把底部栏隐藏了,防止用户直接点进去了

防止下次忘了,记录一下

 navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {
            @Override
            public void onDestinationChanged(@NonNull NavController controller, @NonNull NavDestination destination, @Nullable Bundle arguments) {
                if(destination.getId()==R.id.login||destination.getId()==R.id.regist){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            bottomNavigationView.setVisibility(View.GONE);
                        }
                    });
                }else{
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            bottomNavigationView.setVisibility(View.VISIBLE);
                        }
                    });
                }
                System.out.println(destination.getId()==R.id.login);
            }
        });

kotlin版

 navController.addOnDestinationChangedListener { controller, destination, arguments ->
            if (destination.id == R.id.loginFragment || destination.id == R.id.register) {
                runOnUiThread { navView.setVisibility(View.GONE) }
            } else {
                runOnUiThread { navView.setVisibility(View.VISIBLE) }
            }
            println(destination.id == R.id.loginFragment)
        }

你可能感兴趣的:(BottomNavigationView整体隐藏)