Error inflating class com.google.android.material.navigation.NavigationView after migration to AndroidX

前端 未结 7 925
悲哀的现实
悲哀的现实 2020-12-19 06:11

After I updated my project to AndroidX with targetSdkVersion set to 28, my project crashes on installing it from the store for beta testing.

<
相关标签:
7条回答
  • 2020-12-19 06:32

    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>
    
    0 讨论(0)
  • 2020-12-19 06:32

    In my case, the issue is in navigation.NavigationView app:headerLayout layout I am setting

    <ImageView 
      app:srcCompat="@mipmap/ic_launcher_round"
    /> 
    

    and the problem is with ic_launcher_round because this is inside folder mipmap-anydpi-v26 and I am using android version 7.1.1 that is API Level: 25

    hope this helps anyone

    0 讨论(0)
  • 2020-12-19 06:35

    android.view.InflateException: means there is something wrong in your XML file itself.

    Please check all your dimensions, color resources, and other resources you have assigned in the XML tag.

    Or post your XML file here.

    0 讨论(0)
  • 2020-12-19 06:43

    There are multiple reasons why this error can occur. Check the following and make sure they are proper:

    • Check your code for drawable and color resources used inside the com.google.android.material.navigation.NavigationView you've used, probably in activity_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 in res/drawable-v21.
    • Check if you've used android:backgroundTint() or android:src or similar inside your NavigationView. Since they don't work below android API Level 21, use app:backgroundTint or app:srcCompat instead.
    0 讨论(0)
  • 2020-12-19 06:50

    You can check your XML file. Something wrong in your xml like menu, nav header and other. In my Case, wrong in res/menu/menu.xml

    0 讨论(0)
  • 2020-12-19 06:53

    For those who the chosen answer didn't help them, I've found that had a problem with NavigationView theme and it should be an appCompat theme (at least for me). after creating a new style like:

    <style name="NavView" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        ...
    </style>
    

    and used it with android:theme="@style/NavView" in NavigationView in my mainactivity.xml, the app runs perfectly now.

    0 讨论(0)
提交回复
热议问题