Search code examples
androidandroid-architecture-componentsandroid-jetpackandroid-architecture-navigationandroid-jetpack-navigation

setupWithNavController method for toolbar no longer available?


so previously I had crash with error:

You must call setGraph() before calling getGraph()

then after reading the solution frem here. it is said that I have to use these lines on my gradle

implementation "androidx.navigation:navigation-fragment:2.3.0-alpha02"
implementation "androidx.navigation:navigation-ui:2.3.0-alpha02"

and the error is dissapear. but now I no longer can find setupWithNavController method. usually I use this line

toolbar.setupWithNavController(navController,appBarConfiguration)

but I no longer find that method. what should I do ?

enter image description here


Solution

  • To use any of the NavigationUI Kotlin extension functions, you must use the -ktx version of the dependencies.

    implementation "androidx.navigation:navigation-fragment-ktx:2.3.0-alpha02"
    implementation "androidx.navigation:navigation-ui-ktx:2.3.0-alpha02"