BottomSheetDialog disable dragging

Viewed 5506

I have Bottomsheetdialog with Custom view having EditText and on EditText scrolling bottom sheet goes down, How to disable BottomSheetDialog dragging. Any Help Appreciated.

2 Answers

I might be late, but it works fine for me:

@Override
public void setupDialog(final Dialog dialog, int style) {
    super.setupDialog(dialog, style);

    // This should do the job
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(true);
}

Simple solution, It solved two problem I had.

1- It block the dragging event.

2- It solves the listView scrolling problem

CoordinatorLayout.Behavior<View> behavior;

    View profile_config_layout_bottom_sheet = findViewById(R.id.list_view_audience_profile_config_layout);
    
        CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) profile_config_layout_bottom_sheet.getLayoutParams();
        behavior = layoutParams.getBehavior();
        assert behavior != null;
        ((BottomSheetBehavior<View>) behavior).addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                if (newState == BottomSheetBehavior.STATE_DRAGGING) {
                    ((BottomSheetBehavior<View>) behavior).setState(BottomSheetBehavior.STATE_EXPANDED);
                } 
            }
            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {}
        });

Show the dialog with:

((BottomSheetBehavior) behavior).setState(BottomSheetBehavior.STATE_EXPANDED);
Related