Error inflating class android.support.design.widget.BottomNavigationView & Error inflating class android.support.design.widget.BottomNavigationView

Viewed 1812
Caused by: android.view.InflateException: Binary XML file line #19: Binary XML file line #19: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class android.support.design.widget.BottomNavigationView

gradle source

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.1.0-alpha01'
    implementation 'androidx.cardview:cardview:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

layout xml source

 <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="parent"
        app:menu="@menu/menu_bottomnavigationview">  
 </android.support.design.widget.BottomNavigationView>

what am I missing? does androidstuido still support android.support.design.widget.BottomNavigationView"?

5 Answers

try

implementation 'com.google.android.material:material:1.1.0-alpha10' 

and

<com.google.android.material.bottomnavigation.BottomNavigationView
...
>
</com.google.android.material.bottomnavigation.BottomNavigationView>

Per the documentation, it's

  • added in version 26.1.0

  • belongs to Maven artifact com.android.support:design:27.1.0

Unfortunately, this documentation is for the (old) android.support libraries. This thread discusses how to use BottomNavigationView with the (new) androidx libraries:

How to Setup Jetpack Navigation with material.BottomNavigationView

As both Gabriele Mariotti and RavenYang said, if you're using androidx, you need to:

  • Specify com.google.android.material:material:1.1.0-alpha10 in your build.gradle

    ... **AND ** ...

  • Specify the androidx package com.google.android.material.bottomnavigation.BottomNavigationView in your layout XML.

EXAMPLE (android.support):

dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'com.android.support:appcompat-v7:27.1.1'
   implementation 'com.android.support:design:27.1.1'
   ...

EXAMPLE (androidx):

dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'androidx.appcompat:appcompat:1.0.2'
   implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
   implementation 'com.google.android.material:material:1.1.0-alpha10' 
   ...

You are using androidx libraries. so you have to use

implementation 'com.google.android.material:material:1.2.0-alpha01'

it worked for me.

In my case, I added more than 5 items on the menu which caused the crash. After adding only 5 items in the menu I stopped seeing this crash.

Related