In MainActivity.kt
, I have methods to change its Fragment
.
Here is a method for going to SettingActivity.kt
override fun startSetting() {
Timber.d("startSetting()")
Toast.makeText(activity, "startSetting()", Toast.LENGTH_SHORT).show()
Navigation.findNavController(mView).navigate(R.id.action_initFragment_to_settingFragment)
}
this is nav_graph.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:startDestination="@id/initFragment">
<fragment
android:id="@+id/initFragment"
android:name="come.example.view.main.fragment.InitFragment"
android:label="fragment_init"
tools:layout="@layout/fragment_init">
<action
android:id="@+id/action_initFragment_to_settingFragment"
app:destination="@id/settingFragment"
app:enterAnim="@anim/enter_from_right"
app:exitAnim="@anim/none"
app:popEnterAnim="@anim/none"
app:popExitAnim="@anim/exit_to_right" />
<action
android:id="@+id/action_initFragment_to_webFragment"
app:destination="@id/webFragment"
app:enterAnim="@anim/enter_from_right"
app:exitAnim="@anim/none"
app:popEnterAnim="@anim/none"
app:popExitAnim="@anim/exit_to_right" />
<action ... />
</fragment>
</navigation>
This is enter_from_right.xml
.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="3000"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
Here's exit_to_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="3000"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="100%"
android:toYDelta="0%" />
</set>
This is none.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="3000"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
At the first time, I used fragment id
in MainActivity.kt
to change the fragments. However, it seemed like it can't find the destination correctly. So, I used action id
instead of it. And It seems work. However, enter/exit works incorrectly. But pop works fine.
When I used the default none
option in Navigation Editor, It just shows white screen and then change to the later screen. And when I used my custom none.xml
It just changes without any animation(maybe just blinking)
What's wrong with that?