前言
记录一些Navigation下的NavOptions的使用记录
返回某个Fragment并且传递数据
返回到栈里的某个Fragment,会将在这需要跳转的Fragment的栈前的Fragment全部清出。
Bundle bundle = new Bundle(); bundle.putString(CommunityFragment.CITY_NAME_KEY, bean.getName()); NavOptions navOptions = new NavOptions.Builder() .setPopUpTo(R.id.communityFragment, false) .build(); Navigation.findNavController(getView()).navigate(R.id.communityFragment, bundle, navOptions);
跳转Fragment带动画
NavOptions navOptions = new NavOptions.Builder() .setEnterAnim(R.anim.from_right) //进入动画 .setExitAnim(R.anim.to_left) //退出动画 .setPopEnterAnim(R.anim.to_left) //弹出进入动画 .setPopExitAnim(R.anim.from_right) //弹出退出动画 .build(); controller.navigate(R.id.action_oneFragment_to_twoFragment, null , navOptions);
End