android – What's alternative to 'AppBarLayout$ScrollingViewBehavior' in AndroidX?-ThrowExceptions

Exception or error:

I’ve recently migrated my project to AndroidX. Now when I open specific page of the app that has code below, the app Crashes

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="fill_vertical"
    android:clipToPadding="false"
    app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
    >

Error in Logcat:

android.view.InflateException: Binary XML file line #119: Could not inflate Behavior subclass android.support.design.widget.AppBarLayout$ScrollingViewBehavior
    Caused by: java.lang.RuntimeException: Could not inflate Behavior subclass android.support.design.widget.AppBarLayout$ScrollingViewBehavior

I think I must replace this behavior with it’s alternative in AndroidX. But what is that alternative code?
I searched in https://developer.android.com/jetpack/androidx/migrate. But didn’t find AppBarLayout.

Thanks in advance.

How to solve:

I found the solution.
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'

###

In my case I used this:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

also make sure to add this dependency:

implementation 'com.google.android.material:material:1.0.0'

Leave a Reply

Your email address will not be published. Required fields are marked *