Error inflating com.google.android.material.button.MaterialButton
See original GitHub issueHi everyone.
I’m trying to dynamically inflate a button layout into a recycler view item from my item adapter. Here is how it looks :
LayoutInflater factory = LayoutInflater.from(mContext); View buttonView = factory.inflate(buttonsList.get(position).getLayout(), null); holder.buttonContainer.addView(buttonView);
Basically, my getLayout attribute returns the layout id of the corresponding button item.
Layout looks like this :
<com.google.android.material.button.MaterialButton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/material_button" style="@style/Widget.MaterialComponents.Button" android:layout_width="match_parent" android:layout_height="wrap_content" android:backgroundTint="@color/colorPrimary" android:text="Search" android:textSize="14sp" android:textAllCaps="true" android:fontFamily="@font/raleway_semibold" />
I can inflate basic buttons from the old AppCompat library, but not from the Material Design.
I get the following error :
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class com.google.android.material.button.MaterialButton
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.material.button.MaterialButton
Do you have any idea where the problem comes from ? Is it a library bug ?
Thanks in advance,
Corentin
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (1 by maintainers)
Top GitHub Comments
Try to update your app theme to inherit from Theme.MaterialComponents (or a descendant)
Change your AppTheme parent to Theme.MaterialComponents
Before
After
More