I've been following the sample from NavigationBasicSample
but used newest library for navigation:
implementation "android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha05"
implementation "android.arch.navigation:navigation-ui-ktx:1.0.0-alpha05"
and androidx library:
implementation 'androidx.core:core-ktx:1.0.0-rc01'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-rc01'
and add to bundle.gradle
androidExtensions {
experimental = true
}
all works except animation. It is bug maybe or ?
this is my nav_graph:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@+id/categoryFragment">
<fragment
android:id="@+id/categoryFragment"
android:name="com.sample.CategoriesFragment"
android:label="Categories"
tools:layout="@layout/fragment_categories">
<action
android:id="@+id/action_categoryFragment_to_itemsFragment"
app:destination="@id/itemsFragment"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left" />
</fragment>
<fragment
android:id="@+id/itemsFragment"
android:name="com.sample.ItemsFragment"
android:label="Items"
tools:layout="@layout/fragment_items" >
<argument android:name="cat_id" android:defaultValue="-1" />
</fragment>
</navigation>
and my navhost fragment:
<fragment
android:id="@+id/fragment_nav_host"
app:defaultNavHost="true"
android:name="androidx.navigation.fragment.NavHostFragment"
app:navGraph="@navigation/nav_graph"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
I think you use this code:
findNavController(it, R.id. fragment_nav_host).navigate(R.id. itemsFragment)
If this is true, then it is wrong. You must use the action you wrote with your animation.
Correct will be:
findNavController(it,R.id.fragment_nav_host).navigate(R.id.action_categoryFragment_to_itemsFragment)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.