找不到类“ com.google.android.material.appbar.CollapsingToolbarLayout”

时间:2018-08-20 12:27:03

标签: android android-support-library android-coordinatorlayout

我有致命的异常:

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'

2 个答案:

答案 0 :(得分:2)

这里是代码 使用A代替android.support.design

android.support.design.widget

答案 1 :(得分:0)

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