How to disable BottomSheetDialogFragment dragging

后端 未结 14 1276
猫巷女王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<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) {}
        });
    
    0 讨论(0)
  • 2021-01-31 05:48
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
            super.onViewCreated(view, savedInstanceState)
        //Disable dragging by set isDraggable to false
        val bottomSheetDialog = dialog as BottomSheetDialog
        val bottomSheetBehavior = bottomSheetDialog.behavior
        bottomSheetBehavior.isDraggable = false
    }
    
    0 讨论(0)
提交回复
热议问题