Android 在执行任务之前,需要单击底部导航2次

Android 在执行任务之前,需要单击底部导航2次,android,bottomnavigationview,Android,Bottomnavigationview,我有一个底部导航栏,我不知道为什么,但我需要在执行任务之前单击它两次 这是用于底部导航的xml <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_navigation_view" android:layout_width="match_parent" android:layout_height="wrap_content" ap

我有一个底部导航栏,我不知道为什么,但我需要在执行任务之前单击它两次

这是用于底部导航的xml

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottom_navigation_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:itemBackground="@color/colorPrimary"
    app:itemIconTint="@color/white"
    app:itemTextColor="@color/white"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    android:focusableInTouchMode="true"
    app:menu="@menu/bottom_navigation_admin" />
你用

bottomNavigationView.setOnNavigationItemReselectedListener而不是
bottomNavigationView.setOnNavigationItemSelectedListener

未重新选择仅已选择;)

您使用

bottomNavigationView.setOnNavigationItemReselectedListener而不是
bottomNavigationView.setOnNavigationItemSelectedListener


未重新选择仅已选择;)

您正在设置重新选择侦听器,但需要设置onitem select listener。 替换


您正在设置重新选择侦听器,但需要设置onitem select listener。 替换


您正在使用setOnNavigationItemReselectedListener

用这个
setOnNavigationItemSelectedListener

您正在使用setOnNavigationItemReselectedListener

用这个
setOnNavigationItemSelectedListener

private void setBottomNavigation() {
    BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);
    bottomNavigationView.setOnNavigationItemReselectedListener(new BottomNavigationView.OnNavigationItemReselectedListener() {
        @Override
        public void onNavigationItemReselected(@NonNull MenuItem menuItem) {
            switch (menuItem.getItemId()) {
                case R.id.navigation_override :
                    fragment = new OverrideFragment();
                    fragmentManager.beginTransaction().replace(R.id.fragment_layout, fragment).commit();
                    break;
                case R.id.navigation_user:
                    fragment = new UserListFragment();
                    fragmentManager.beginTransaction().replace(R.id.fragment_layout, fragment).commit();
                    break;
                case R.id.navigation_log_out:
                    CustomDialog customDialog = new CustomDialog(AdminBoardActivity.this);
                    customDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    customDialog.show();
                    break;
            }
        }
    });
}
 bottomNavigationView.setOnNavigationItemReselectedListener()
BottomNavigationView.OnNavigationItemSelectedListener()