Android material chip component crashing app. Unable to inflate xml

Sourin Ghosh picture Sourin Ghosh · Aug 16, 2018 · Viewed 19.3k times · Source

Tried Chip component from both support library
com.google.android.support:design:28.0.0-rc01 and material
com.google.android.material:material:1.0.0-rc01

StackTrace

android.view.InflateException: Binary XML file line #72: Binary XML file 
      line #72: Error inflating class com.google.android.material.chip.Chip 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:429)`

Layout

<com.google.android.material.chip.Chip
    android:id="@+id/chip"
    style="style/Widget.MaterialComponents.Chip.Entry"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/account"
    app:closeIconEnabled="true" />`

Answer

Mikhail Sharin picture Mikhail Sharin · Sep 13, 2018

Update your app theme to inherit from one of these themes:

Theme.MaterialComponents
Theme.MaterialComponents.NoActionBar
Theme.MaterialComponents.Light
Theme.MaterialComponents.Light.NoActionBar
Theme.MaterialComponents.Light.DarkActionBar

For example:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">

Note: Using a Material Components theme enables a custom view inflater

Source: https://www.material.io/develop/android/docs/getting-started/