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

后端 未结 13 1589
甜味超标
甜味超标 2020-12-08 09:39

I would like use a FloatingActionButton on my application, I read this : https://guides.codepath.com/android/Floating-Action-Buttons#google-s-official-support-library but wh

相关标签:
13条回答
  • 2020-12-08 10:18

    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'
    
    0 讨论(0)
  • 2020-12-08 10:20

    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>
      
    0 讨论(0)
  • 2020-12-08 10:21

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

    0 讨论(0)
  • 2020-12-08 10:26

    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

    0 讨论(0)
  • 2020-12-08 10:27

    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! :)
    0 讨论(0)
  • 2020-12-08 10:27

    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 .

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