Reputation: 8919
I am using Navigation Components library. When navigating to another fragment, to use animation, I understand that I can add xml code like this:
<fragment
android:id="@+id/specifyAmountFragment"
android:name="com.example.buybuddy.buybuddy.SpecifyAmountFragment"
android:label="fragment_specify_amount"
tools:layout="@layout/fragment_specify_amount">
<action
android:id="@+id/confirmationAction"
app:destination="@id/confirmationFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
But, I need to use it programmatically.
I would appreciate your answer.
Upvotes: 1
Views: 2055
Reputation: 8919
I found the answer and I just want to share with you.
You can use NavOptions
in this way:
val action = HomeFragmentDirections.actionHomeFragmentToFilesFragment2()
val navOptions = NavOptions
.Builder()
.setEnterAnim(R.anim.fragment_open_enter)
.setExitAnim(R.anim.fragment_close_exit)
.setPopEnterAnim(R.anim.fragment_open_enter)
.setPopExitAnim(R.anim.fragment_close_exit)
.build()
findNavController().navigate(action, navOptions)
Upvotes: 4