BottomNavigationView 不存在
BottomNavigationView Does not exists
我正在尝试将 navigationeditor 与底部导航视图一起使用,但似乎是 bottomnavigationview 才导致了这个问题。
这是我的 xml :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph"
/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
这是 gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.wedding.rashmilind"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation "com.android.support:support-v4:28.0.0"
implementation "com.android.support:support-v4:28.0.0"
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0-alpha04'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha04'
implementation 'android.arch.navigation:navigation-fragment:1.0.0'
implementation 'android.arch.navigation:navigation-ui:1.0.0'
}
这是我在运行代码时遇到的错误:
Caused by: android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.BottomNavigationView" on path: DexPathList[[zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/base.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_resources_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/lib/arm64, /system/lib64, /vendor/lib64]]
它只得到这个视图:com.google.android.material.bottomnavigation.BottomNavigationView
因为您已迁移到 AndroidX...请尝试改用 com.google.android.material.bottomnavigation.BottomNavigationView
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
ON MAC CMD+SHIFT+R
然后替换所有出现的
android.support.design.widget.BottomNavigationView
有
com.google.android.material.bottomnavigation.BottomNavigationView
我正在尝试将 navigationeditor 与底部导航视图一起使用,但似乎是 bottomnavigationview 才导致了这个问题。
这是我的 xml :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph"
/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
这是 gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.wedding.rashmilind"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation "com.android.support:support-v4:28.0.0"
implementation "com.android.support:support-v4:28.0.0"
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0-alpha04'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha04'
implementation 'android.arch.navigation:navigation-fragment:1.0.0'
implementation 'android.arch.navigation:navigation-ui:1.0.0'
}
这是我在运行代码时遇到的错误:
Caused by: android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.BottomNavigationView" on path: DexPathList[[zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/base.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_resources_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.wedding.rashmilind-zTaNp816F4MRKuZ8FBDtjw==/lib/arm64, /system/lib64, /vendor/lib64]]
它只得到这个视图:com.google.android.material.bottomnavigation.BottomNavigationView
因为您已迁移到 AndroidX...请尝试改用 com.google.android.material.bottomnavigation.BottomNavigationView
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
ON MAC CMD+SHIFT+R
然后替换所有出现的
android.support.design.widget.BottomNavigationView
有
com.google.android.material.bottomnavigation.BottomNavigationView