1,action
在navigation_main.xml中设置action
action设置好了之后,我们可以执行下面代码进行跳转:
findNavController().navigate(R.id.action_homeSampleFragment_to_dashBoardSampleFragment_action)
2,NavOptions切换动画
NavOptions是一个动画管理类,我们可以设置进入和回退的动画,设置的方式有两种:
a,直接在标签中设置动画
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"/>
b,通过NavOptions设置动画
val options = navOptions {
anim {
enter = R.anim.slide_in_right
exit = R.anim.slide_out_left
popEnter = R.anim.slide_in_left
popExit = R.anim.slide_out_right
}
}
view.findViewById
app:argType=""
android:defaultValue=""
app:nullable=""/>
val args = Bundle()
args.putString("link","1")
args.putString("title","1")
it.findNavController().navigate(R.id.webFragment, args)
ConfirmationFragmentArgs
override fun onClick(v: View) { val amountTv: EditText = view!!.findViewById(R.id.editTextAmount) val amount = amountTv.text.toString().toInt() val action = SpecifyAmountFragmentDirections.confirmationAction(amount) v.findNavController().navigate(action) }
val args: ConfirmationFragmentArgs by navArgs() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { val tv: TextView = view.findViewById(R.id.textViewAmount) val amount = args.amount tv.text = amount.toString() }