animateLayoutChanges=”true” in BottomSheetView showing unexpected behaviour

The BottomSheetBehavior does not work well with LayoutTransition (animateLayoutChanges=”true”) for now. I will work on a fix. For now, you can use Transition instead. Something like this will fade the view inside and animate the size of the bottom sheet. ViewGroup bottomSheet = …; View hidingView = …; TransitionManager.beginDelayedTransition(bottomSheet); hidingView.setVisibility(View.GONE); You can refer to Applying … Read more

BottomSheetDialogFragment – listen to dismissed by user event

Although all similar questions on SO suggest using onDismiss I think following is the correct solution: @Override public void onCancel(DialogInterface dialog) { super.onCancel(dialog); Toast.makeText(MainApp.get(), “CANCEL”, Toast.LENGTH_SHORT).show(); } This fires if: * the user presses back * the user presses outside of the dialog This fires NOT: * on screen rotation and activity recreation Solution Combine … Read more

bottomSheetDialogFragment full screen

In your custom BottomSheetDialogFragment you can use something like: @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { BottomSheetDialog bottomSheetDialog = (BottomSheetDialog) dialogInterface; setupFullHeight(bottomSheetDialog); } }); return dialog; } private void setupFullHeight(BottomSheetDialog bottomSheetDialog) { FrameLayout bottomSheet = (FrameLayout) bottomSheetDialog.findViewById(R.id.design_bottom_sheet); BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet); ViewGroup.LayoutParams … Read more

Prevent BottomSheetDialogFragment covering navigation bar

I had the same problem and I finally found a solution which is not hacky or needs an exorbitant amount of code. This Method replaced the window background with a LayerDrawable which consists of two elements: the background dim and the navigation bar background. @RequiresApi(api = Build.VERSION_CODES.M) private void setWhiteNavigationBar(@NonNull Dialog dialog) { Window window … Read more

BottomSheetDialogFragment – How to set expanded height (or min top offset)

The height is being wrapped because the inflated view is added to the FrameLayout which has layout_height=wrap_content. See FrameLayout (R.id.design_bottom_sheet) at https://github.com/dandar3/android-support-design/blob/master/res/layout/design_bottom_sheet_dialog.xml. The class below makes the bottom sheet full screen, background transparent, and fully expanded to the top. public class FullScreenBottomSheetDialogFragment extends BottomSheetDialogFragment { @CallSuper @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { … Read more

Show entire bottom sheet with EditText above Keyboard

Just reposting @jblejder from this question Keyboard hides BottomSheetDialogFragment since it worked for me, to make it easier for others to find: The most convenient way that I found to change this is by creating style: <style name=”DialogStyle” parent=”Theme.Design.Light.BottomSheetDialog”> <item name=”android:windowIsFloating”>false</item> <item name=”android:statusBarColor”>@android:color/transparent</item> <item name=”android:windowSoftInputMode”>adjustResize</item> </style> And set this in onCreate method of your BottomSheetDialogFragment: … Read more

BottomSheetBehavior not in androidX libraries

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 … Read more

Disabling User dragging on BottomSheet

It can be now no longer relevant, but I will leave it here: import android.content.Context import android.util.AttributeSet import androidx.coordinatorlayout.widget.CoordinatorLayout import android.view.MotionEvent import android.view.View import com.google.android.material.bottomsheet.BottomSheetBehavior @Suppress(“unused”) class LockableBottomSheetBehavior<V : View> : BottomSheetBehavior<V> { constructor() : super() constructor(context: Context, attrs: AttributeSet) : super(context, attrs) var swipeEnabled = true override fun onInterceptTouchEvent( parent: CoordinatorLayout, child: V, event: … Read more