切换Fragment时Navagation Selected状态如何解决?

问题描述 投票:0回答:1

第一步:通过导航控制器将home_fragment切换到dashboard_fragment 第二步:将dashboard_fragment切换为scan_fragment,如下

@Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment);
                navController.navigate(R.id.dashToScan);
            }

第三步:将scan_fragment切换为notification_fragment

第四步:通过navigation控制器将notification_fragment切换到dashboard_fragment

第四步后,显示 scan_fragment,但导航仍处于通知状态

如下图所示 the problem is that the Dashboard item is not selected

任何人都可以给我一些关于如何解决这个问题的建议吗?

我尝试如下 在 onDestinationChanged

navView.setSelectedItemId(R.id.navigation_dashboard);
navView.getMenu().findItem(R.id.navigation_dashboard).setChecked(true);
java android navigation fragment
1个回答
0
投票

尝试清除焦点

@Override
public void onClick(View v) {
    NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment);
    navController.navigate(R.id.dashToScan);
    v.clearFocus();
}
© www.soinside.com 2019 - 2024. All rights reserved.