Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's alternative to 'AppBarLayout$ScrollingViewBehavior' in AndroidX?

Tags:

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.

like image 249
DrMorteza Avatar asked Oct 30 '18 10:10

DrMorteza


People also ask

When to use AppBarLayout in android?

The AppBarLayout is used to achieve various scrolling behaviors such as collapse, flex space, and quick return.

What is app Layout_behavior string Appbar_scrolling_view_behavior?

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.

How do I add an app to the layout bar?

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.


Video Answer


1 Answers

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' 
like image 51
DrMorteza Avatar answered Sep 21 '22 04:09

DrMorteza