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'
Author by
tarunsmalviya12
Updated on July 14, 2022Comments
-
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 over 7 yearsThe above code is in android.support.design.widget.CoordinatorLayout.
-
Mike M. over 7 yearsIt seems like you've set your own (incorrect) value for the
appbar_scrolling_view_behavior
Resource String. The value in the support library isandroid.support.design.widget.AppBarLayout$ScrollingViewBehavior
. Look in yourres/values*/
folders, most likely in astrings.xml
file, to see if you have a value there. If so, delete it. -
Mike M. over 7 yearsRight, that's what you get when
CoordinatorLayout
can't create an instance of a class specified inlayout_behavior
. Somewhere it's trying to create an instance ofandroid.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 over 7 yearsOh sorry! I have declared a string variable with same key. Thanks @MikeM.
-
-
Michael DiCioccio about 4 yearsThank you!!! I was using
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
and replaced it with recommendation.