Error inflating class android.support.design.widget.CoordinatorLayout

巧了我就是萌 提交于 2019-11-28 07:12:47

Please change it into AppCompatActivity if you use Activity. Probably it becomes the error when it is Activity.

Preet Jay

Just use this line in FloatingActionButton (app instead of android):

app:backgroundTint="@color/colorAccent"
rakesh rajput

Please put compile 'com.android.support:design:23.0.1' inside your project build.gradle file

I had the same error. Just change the project parent theme to

<style name="Base.AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

or any other Theme.AppCompat*

For those using AndroidX Dependency

Along with changing dependencies, XML must also be changed.

from

<android.support.design.widget.CoordinatorLayout 

to

<androidx.coordinatorlayout.widget.CoordinatorLayout

You have to include the support libraries.

  1. Go to "Project Structure" -> Dependencies
  2. On the right side click "+" and select "1. Library dependency"
  3. Search for "android.support"
  4. Add both:
    • com.android.support:appcompat-v7:.......
    • com.android.support:design:........
  5. Sync Gradle

    Happy codding! :)

needed both:

  • extend AppCompatActivity instead of FragmentActivity

    public class MyActivity extends AppCompatActivity
    
  • parent of used style (/res/values/styles.xml)

    <style name="MyStyle" parent="Theme.AppCompat">
    

additionally:

  • define colors in styles.xml

    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
    

For Xamarin Developers:

(supports Android API 7 to 22+)

  1. Make sure you have installed following components:
    • Android Support Design Library
    • Android Support Library v7 AppCompat
  2. Make sure all NuGet packages for these components are installed and referenced. These are:
    • Xamarin.Android.Support.Design
    • Xamarin.Android.Support.v4
    • Xamarin.Android.Support.v7.AppCompat
    • Xamarin.Android.Support.v7.RecyclerView
  3. Your Apps Activity should derive from Android.Support.V7.App.AppCompatActivity
  4. Your used style has to be derived from a Theme.AppCompat.* style. So your Resources\values\styles.xml should look like this:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="YourAppTheme" parent="Theme.AppCompat">
            <item name="colorPrimaryDark">#AB000D</item>
            <item name="colorPrimary">#E53935</item>
            <item name="colorAccent">#00B8D4</item>
        </style>
        <!-- other styles... -->
    </resources>
    
  5. Also make sure you actually use the theme in your AndroidManifest.xml

    <application android:theme="@style/YourAppTheme"></application>
    
FN90

Add these dependencies into your gradle file. This may solve the problem in some cases.

dependencies {
   compile 'com.android.support:appcompat-v7:23.1.1'
   compile 'com.android.support:design:23.1.1'
   ...
}
Josi

You need to add in your app's build gradle the following support library.

    compile 'com.android.support:design:23.0.1'

that was last year, now the latest version is

    compile 'com.android.support:design:27.0.2'

For me, I came across this error when using a mix of androidx and android.support.v7 libraries.

See my solution for that version of this error here: https://stackoverflow.com/a/52490825/1762493

For those using AndroidX Dependency. In your xml files make sure all your

 android.support.???

nodes inside CoordinatorLayout's (like included ActionBars) are also replaced with

androidx.??? (or com.google.android.???)

ones .

It worked for me

Disable Instant Run

File => Settings => Build, Execution, Deployment => Instant Run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!