BottomNavigationView全体非表示

7492 ワード

ログイン登録時に下のバーを隠して、ユーザーが直接クリックしないようにする必要があります.
次回忘れないように記録しておきます
 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)
        }