Could not inflate Behavior subclass android.support.design.widget.scroll_behavior

11,277

The layout_behavior line must be replace with this:

app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"

make sure this dependency exists in build.gradle:

implementation 'com.google.android.material:material:1.0.0'
Share:
11,277
tarunsmalviya12
Author by

tarunsmalviya12

Updated on July 14, 2022

Comments

  • tarunsmalviya12
    tarunsmalviya12 almost 2 years

    Here is my activity in which I have used coordinate layout and view pager.

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">
    
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="@dimen/app_bar_height"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
    
            <include layout="@layout/venue_app_bar_content" />
    
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />
    
            <android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="bottom"
                app:tabIndicatorColor="@android:color/white"
                app:tabMode="scrollable"
                app:tabSelectedTextColor="@color/white"
                app:tabTextColor="@color/white50" />
    
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
    
    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    

    When run app, it get crashed with message : Caused by: java.lang.RuntimeException: Could not inflate Behavior subclass android.support.design.widget.scroll_behavior

    • tarunsmalviya12
      tarunsmalviya12 over 7 years
      The above code is in android.support.design.widget.CoordinatorLayout.
    • Mike M.
      Mike M. over 7 years
      It seems like you've set your own (incorrect) value for the appbar_scrolling_view_behavior Resource String. The value in the support library is android.support.design.widget.AppBarLayout$ScrollingViewBeha‌​vior. Look in your res/values*/ folders, most likely in a strings.xml file, to see if you have a value there. If so, delete it.
    • Mike M.
      Mike M. over 7 years
      Right, that's what you get when CoordinatorLayout can't create an instance of a class specified in layout_behavior. Somewhere it's trying to create an instance of android.support.design.widget.scroll_behavior, so figure out wherever it's getting that incorrect class name from. The rest of your stack trace would help you find out where, if it's not coming from what you posted.
    • tarunsmalviya12
      tarunsmalviya12 over 7 years
      Oh sorry! I have declared a string variable with same key. Thanks @MikeM.
  • Michael DiCioccio
    Michael DiCioccio about 4 years
    Thank you!!! I was using app:layout_behavior="android.support.design.widget.AppBarLay‌​out$ScrollingViewBeh‌​avior" and replaced it with recommendation.