没找到 class "com.google.android.material.appbar.CollapsingToolbarLayout"

Didn't find class "com.google.android.material.appbar.CollapsingToolbarLayout"

我遇到致命异常:

E/AndroidRuntime: FATAL EXCEPTION: main
                      Process: com.TEST.TEST, PID: 27236
                      android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.google.android.material.appbar.CollapsingToolbarLayout
                      Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class com.google.android.material.appbar.CollapsingToolbarLayout
    enter code here
                      Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.material.appbar.CollapsingToolbarLayout" 

这里是xml我用的是:

<?xml version="1.0" encoding="utf-8"?>

<ProgressBar
    android:id="@+id/progressTickets"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:indeterminate="true" />

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleGravity="top"
        app:expandedTitleMarginStart="10dp"
        app:expandedTitleMarginTop="10dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

        <LinearLayout
            android:id="@+id/llBuyTickets"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="@font/montserrat_bold"
                android:text="@string/buy_ticket"
                android:textColor="@color/colorDarkGreen"
                android:textSize="9pt" />


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:fontFamily="@font/roboto_regular"
                android:text="@string/buy_ticket_description"
                android:textColor="@color/colorDarkGreen" />

            <HorizontalScrollView
                android:id="@+id/svTicketTypes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/content_padding_medium"
                android:layout_marginTop="@dimen/content_padding_medium"
                android:scrollbars="none">

                <LinearLayout
                    android:id="@+id/llTicketTypes"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:orientation="horizontal" />

            </HorizontalScrollView>

            <Button
                android:id="@+id/btnBuyTicket"
                style="@style/AlertDialog.AppCompat.Light"
                android:layout_width="match_parent"
                android:layout_height="@dimen/view_auth_item_size"
                android:background="@drawable/view_rounded_accent_bg"
                android:enabled="false"
                android:fontFamily="@font/montserrat_bold"
                android:text="@string/confirm_purchase"
                android:textColor="@color/white" />
        </LinearLayout>


        <android.support.v7.widget.Toolbar
            android:id="@+id/AppBar"
            android:layout_width="match_parent"
            android:layout_height="10dp"
            app:layout_collapseMode="pin" />


    </com.google.android.material.appbar.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>


<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:fontFamily="@font/montserrat_bold"
    android:text="@string/my_ticket"
    android:textColor="@color/colorDarkGreen"
    android:textSize="9pt" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/rvTickets"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

目标版本是:27 最小版本为:21

这里是 gradle 文件:

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'

您正在使用 com.google.android.material.appbar.CollapsingToolbarLayout,您在其中具有设计支持依赖性。所以你必须使用 android.support.design.widget.CollapsingToolbarLayout

这是代码 使用 android.support.design 而不是 android.support.design.widget

<android.support.design.widget.CollapsingToolbarLayout 
   android:id="@+id/collapsing_toolbar" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   app:layout_scrollFlags="scroll|exitUntilCollapsed" 
   app:contentScrim="?attr/colorPrimary"/>