question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error inflating com.google.android.material.button.MaterialButton

See original GitHub issue

Hi 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:closed
  • Created 5 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

119reactions
gothamitecommented, Mar 11, 2019

Try to update your app theme to inherit from Theme.MaterialComponents (or a descendant)

88reactions
Twibapcommented, Jun 20, 2019

Change your AppTheme parent to Theme.MaterialComponents

Before

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

After

    <!-- Material application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

More

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Error inflating class com.google.android.material.button ...
material.button.MaterialButton Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.
Read more >
MaterialButton - Android Developers
A convenience class for creating a new Material button. This class supplies updated Material styles for the button in the constructor.
Read more >
com.google.android.material.button.MaterialButton
This page shows Java code examples of com.google.android.material.button. ... View view = layoutInflater.inflate( R.layout.cat_shape_theming_container, ...
Read more >
How to Implement Material Button in Android Studio - YouTube
Material Button Tutorial : In This Video, You Will Learn How to Integrate Material Button in Android Studio.Build.
Read more >
Error inflating class com.google.android.material.button ...
Error inflating class com.google.android.material.button.MaterialButton. El error nos indica que al querer instanciar y mostrar el ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found