Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BottomSheetBehavior not in androidX libraries

I was using the BottomSheetBehavior with the original support library:

implementation 'com.android.support:design:27.1.1'  

When I migrated to use the new androidx libraries though the BottomSheetBehavior is missing. The mapping from the above support library isn't in the AndroidX Refactoring List either, but the migration tool removed it.

What am I missing to include the BottomSheetBehavior with the new androidx libraries.

dependencies {     implementation fileTree(dir: 'libs', include: ['*.jar'])     implementation 'com.google.android.material:material:1.0.0-beta01'     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"      // ReactiveX     implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'     implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'      implementation 'com.android.support:design:28.1.0'      // Android Compatability Libraries     // Version: https://developer.android.com/topic/libraries/support-library/refactor     implementation 'androidx.appcompat:appcompat:1.0.0-beta01'     implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha1'     implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'     implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-beta01'     implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'      // Android Navigation Component     // Check here for updated version info - will move to androidx soon.     // https://developer.android.com/topic/libraries/architecture/adding-components     def nav_version = "1.0.0-alpha04"      // use -ktx for Kotlin     implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"     implementation "android.arch.navigation:navigation-ui-ktx:$nav_version"     androidTestImplementation "android.arch.navigation:navigation-testing-ktx:$nav_version"      // Testing     testImplementation 'junit:junit:4.12'     androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'     androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4' } 
like image 387
Jim Leask Avatar asked Jul 31 '18 15:07

Jim Leask


People also ask

How to make bottom sheet not dismissable?

How do I make my bottom sheet not dismissable? You should use #setCancelable(false) when you create an instance of it.

What is bottom sheet behavior?

Android Bottom Sheet is a component that slides up from the bottom of the screen having multiple options. Here are the examples of the Bottom sheet from apps. There are two types of bottom sheets, Persistent Bottom Sheet and Modal Bottom Sheet.

How to close bottomSheetDialog?

We use bottomSheetDialog. dismiss() to close the dialog once an element is clicked. You can also set a more distinct action, instructing your application to do something when the dialog is dismissed. For instance, the app can launch a new activity.

What is persistent bottom sheet?

In android, there are two types of bottom sheets that use most of the time, Persistent Bottom Sheet and Modal Bottom Sheet. Persistent Bottom Sheet: It shows in-app content. It will display at the bottom of the mobile screen making some amount of the content visible.


1 Answers

It turns out that the refactor tool in Android Studio Refactor > Migrate to AndroidX didn't correctly migrate the XML for the BottomSheetBehaviour.

The old location was android.support.design.widget.BottomSheetBehavior, and was not modified by the migration tool. The original XML was:

<fragment     android:id="@+id/player_bottom_sheet_fragment"     android:name="app.rxsongbrowsertrials.ui.player.PlayerToggleFragment"     android:layout_width="match_parent"     android:layout_height="match_parent"     app:behavior_hideable="false"     app:behavior_peekHeight="56dp"     app:layout_behavior="android.support.design.widget.BottomSheetBehavior"     /> 

The new location is com.google.android.material.bottomsheet.BottomSheetBehavior, so the layout needs to become:

<fragment     android:id="@+id/player_bottom_sheet_fragment"     android:name="app.rxsongbrowsertrials.ui.player.PlayerToggleFragment"     android:layout_width="match_parent"     android:layout_height="match_parent"     app:behavior_hideable="false"     app:behavior_peekHeight="56dp"     app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"     /> 
like image 82
Jim Leask Avatar answered Sep 23 '22 02:09

Jim Leask