NavHostFragment not accessible from XML

前端 未结 6 1596
天涯浪人
天涯浪人 2021-02-14 06:08

I wanted to try new Navigation library. After following this guideline I experienced error at runtime:

Caused by: android.view.InflateException: Binary XML file          


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-14 06:33

    NavHostFragment is not accessible?android:name="androidx.navigation.fragment.NavHostFragment

    So in your build.gradle, just add this two dependencies -

    For Java:-

    dependencies {
    def nav_version = "2.3.0"
    
    implementation "androidx.navigation:navigation-fragment:$nav_version"
    implementation "androidx.navigation:navigation-ui:$nav_version"
    
    }
    

    For Kotlin:-

    dependencies {
    def nav_version = "2.3.0"
    
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
    
    }
    

    Reference Link:- https://developer.android.com/jetpack/androidx/releases/navigation

提交回复
热议问题