How to disable BottomSheetDialogFragment dragging

后端 未结 14 1284
猫巷女王i
猫巷女王i 2021-01-31 04:58

How to disable BottomSheetDialogFragment dragging by finger?

I saw similar questions, but they\'re all about BottomSheet not BottomSheetD

14条回答
  •  走了就别回头了
    2021-01-31 05:46

    Simple solution

        CoordinatorLayout.Behavior 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) behavior).addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                if (newState == BottomSheetBehavior.STATE_DRAGGING) {
                    ((BottomSheetBehavior) behavior).setState(BottomSheetBehavior.STATE_EXPANDED);
                } 
            }
            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {}
        });
    

提交回复
热议问题