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.
The AppBarLayout is used to achieve various scrolling behaviors such as collapse, flex space, and quick return.
The support library contains a special string resource @string/appbar_scrolling_view_behavior that maps to AppBarLayout. ScrollingViewBehavior , which is used to notify the AppBarLayout when scroll events occur on this particular view. The behavior must be established on the view that triggers the event.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken app bar layout and recycler view.
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 'material' dependency exists in build.gradle:
implementation 'com.google.android.material:material:1.2.1'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With