Error inflating class com.google.android.material.navigation.NavigationView after migration to AndroidX
There are multiple reasons why this error can occur. Check the following and make sure they are proper:
- Check your code for
drawable
andcolor
resources used inside thecom.google.android.material.navigation.NavigationView
you've used, probably inactivity_main.xml
, if you're using the default Navigation Drawer template code from Android Studio. - Check that the drawable files are in
res/drawable
folder, not inres/drawable-v21
. - Check if you've used
android:backgroundTint()
orandroid:src
or similar inside yourNavigationView
. Since they don't work below android API Level 21, useapp:backgroundTint
orapp:srcCompat
instead.
In my case the problem was the theme value in the Manifest file
<activity
android:name=".ui.BarcodeReaderDrawerActivity"
android:label="@string/title_activity_barcode_reader_drawer">
android:theme="@style/AppBaseTheme.NoActionBar"
</activity>
Changed in
<activity
android:name=".ui.BarcodeReaderDrawerActivity"
android:label="@string/title_activity_barcode_reader_drawer"
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar">
</activity>